70 exercises in 20 chapters, from first s-expressions to restarts, macros, CLOS, and a tiny Lisp interpreter. Each exercise ships broken with a solved twin and a hint. Includes a watch-mode runner, a plain-CL check harness, a nix flake, and verification tooling. All plain SBCL, no dependencies.
30 lines
681 B
Common Lisp
30 lines
681 B
Common Lisp
;;; PACKAGES 3: USING ANOTHER PACKAGE (solution)
|
|
|
|
(defpackage #:shapes
|
|
(:use #:common-lisp)
|
|
(:export #:area))
|
|
|
|
(in-package #:shapes)
|
|
|
|
(defun area (s)
|
|
(* s s))
|
|
|
|
(defpackage #:studio
|
|
(:use #:common-lisp #:shapes)
|
|
(:export #:total))
|
|
|
|
(in-package #:studio)
|
|
|
|
(defun total (a b)
|
|
(+ (area a) (area b)))
|
|
|
|
;;; ------------------------------------------------------------------
|
|
;;; Checks. Read them - they tell you what to aim for - but leave
|
|
;;; them unchanged. (Checks run back in the user package.)
|
|
;;; ------------------------------------------------------------------
|
|
|
|
(in-package #:common-lisp-user)
|
|
|
|
(check-equal 13 (studio:total 2 3))
|
|
(check-equal 5 (studio:total 1 2))
|