Fix 14 wave-4 re-review findings (batches w4a+w4b)
This commit is contained in:
1 parent
a28a35991f
commit
fd5e11cdeb
23 files changed
+98
-29
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
# 01_sexps
|
# 01_sexps
|
||||||
|
|
||||||
S-expressions: prefix notation, nesting, and `quote`.
|
S-expressions: prefix notation, nesting, `quote`, and reader shorthand.
|
||||||
|
|
||||||
Everything in Lisp is built from parenthesized forms with the operator
|
Everything in Lisp is built from parenthesized forms with the operator
|
||||||
first. No precedence rules, no ambiguity: the shape of the code is the
|
first. No precedence rules, no ambiguity: the shape of the code is the
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
# 04_conditionals
|
# 04_conditionals
|
||||||
|
|
||||||
IF, COND, WHEN, UNLESS, and the value-returning AND and OR.
|
IF, COND, WHEN, UNLESS, and the value-returning AND and OR. CASE and
|
||||||
|
ECASE dispatch on one value.
|
||||||
|
|
||||||
NIL is the only false value. Zero and the empty string are true, and
|
NIL is the only false value. Zero and the empty string are true, and
|
||||||
the empty list IS nil - watch for that one.
|
the empty list IS nil - watch for that one.
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
;;; too: (eql 1 1.0) is NIL.
|
;;; too: (eql 1 1.0) is NIL.
|
||||||
;;; EQUALP the generous one: numbers by value - (equalp 1 1.0) is
|
;;; EQUALP the generous one: numbers by value - (equalp 1 1.0) is
|
||||||
;;; T - characters ignoring case.
|
;;; T - characters ignoring case.
|
||||||
|
;;; A character is written #\a - and #\A is another one.
|
||||||
;;;
|
;;;
|
||||||
;;; Fix each definition with the comparison its comment names.
|
;;; Fix each definition with the comparison its comment names.
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
# 06_lists
|
# 06_lists
|
||||||
|
|
||||||
CONS cells, CAR and CDR, list building, association lists.
|
CONS cells, CAR and CDR, list building, association lists.
|
||||||
|
DESTRUCTURING-BIND binds a whole list of names at once.
|
||||||
|
|
||||||
A list is a chain of pairs ending in NIL. Quote writes lists as data;
|
A list is a chain of pairs ending in NIL. Quote writes lists as data;
|
||||||
LIST and CONS build them at runtime. Association lists map keys to
|
LIST and CONS build them at runtime. Association lists map keys to
|
||||||
|
|||||||
@@ -2,5 +2,6 @@
|
|||||||
|
|
||||||
Lists and recursion grew up together.
|
Lists and recursion grew up together.
|
||||||
|
|
||||||
The shape is always the same: a base case for NIL, a step that
|
The shape is always the same: a base case, a shrinking step, and
|
||||||
consumes one element, and trust that the rest is already solved.
|
trust that the rest is already solved. Lists lose an element at a
|
||||||
|
time, numbers count down - and sometimes two functions take turns.
|
||||||
@@ -3,4 +3,6 @@
|
|||||||
DOLIST, DOTIMES, and the LOOP macro.
|
DOLIST, DOTIMES, and the LOOP macro.
|
||||||
|
|
||||||
DOLIST and DOTIMES are simple walkers. LOOP is a composable
|
DOLIST and DOTIMES are simple walkers. LOOP is a composable
|
||||||
sublanguage: FOR ... COLLECT, SUM, WHEN, THEREIS.
|
sublanguage: FOR ... COLLECT, SUM, WHEN, THEREIS. DO and DO* spell
|
||||||
|
a loop out by hand, and LOOP answers with WITH, THEN, UNTIL, COUNT,
|
||||||
|
MAXIMIZE, and LOOP-FINISH for leaving early.
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
;;; LOOPS 6: COUNT, MAXIMIZE, LOOP-FINISH
|
;;; LOOPS 6: COUNT, MAXIMIZE, LOOP-FINISH
|
||||||
;;;
|
;;;
|
||||||
;;; LOOP accumulates more than lists: COUNT tallies the iterations
|
;;; LOOP accumulates more than lists: COUNT tallies the iterations
|
||||||
;;; whose test is true, MAXIMIZE tracks the biggest value seen (0
|
;;; whose test is true, MAXIMIZE tracks the biggest value seen -
|
||||||
;;; for an empty run, so WIDEST below answers NIL itself).
|
;;; what an empty run answers is implementation-dependent (0 in
|
||||||
|
;;; SBCL), so WIDEST below handles the empty case itself.
|
||||||
;;;
|
;;;
|
||||||
;;; LOOP-FINISH leaves the iterations early, gently: the FINALLY
|
;;; LOOP-FINISH leaves the iterations early, gently: the FINALLY
|
||||||
;;; clause still runs, so (finally (return total)) hands the value
|
;;; clause still runs, so (finally (return total)) hands the value
|
||||||
|
|||||||
@@ -3,4 +3,5 @@
|
|||||||
The number tower: integers, rationals, floats.
|
The number tower: integers, rationals, floats.
|
||||||
|
|
||||||
Integers grow without limit and (/ 7 2) is the exact rational 7/2.
|
Integers grow without limit and (/ 7 2) is the exact rational 7/2.
|
||||||
FLOOR, MOD and friends round and divide with exact rules.
|
FLOOR, MOD and friends round and divide with exact rules. DECLARE
|
||||||
|
promises a type to the compiler; CHECK-TYPE checks it live.
|
||||||
@@ -4,4 +4,4 @@ MAKE-HASH-TABLE, GETHASH, presence, and counting.
|
|||||||
|
|
||||||
GETHASH returns two values: the stored value, and whether the key
|
GETHASH returns two values: the stored value, and whether the key
|
||||||
exists at all. That second value is the honest answer to "is it
|
exists at all. That second value is the honest answer to "is it
|
||||||
there?"
|
there?" MAPHASH walks every pair without you holding the keys.
|
||||||
@@ -4,4 +4,6 @@ DEFPACKAGE, IN-PACKAGE, exports, and :USE.
|
|||||||
|
|
||||||
A package is a namespace. Only exported symbols are visible through
|
A package is a namespace. Only exported symbols are visible through
|
||||||
a single colon; :USE imports them all, the way CL-USER uses
|
a single colon; :USE imports them all, the way CL-USER uses
|
||||||
COMMON-LISP.
|
COMMON-LISP. FIND-SYMBOL looks a name up and INTERN makes-or-finds
|
||||||
|
it; :NICKNAMES give a package other names to answer to, and :SHADOW
|
||||||
|
claims a name before a USEd package can lend its own.
|
||||||
@@ -2,10 +2,12 @@
|
|||||||
;;;
|
;;;
|
||||||
;;; A single colon reaches only EXPORTED symbols. The double colon
|
;;; A single colon reaches only EXPORTED symbols. The double colon
|
||||||
;;; shop::secret-sale reaches the internal ones too. :NICKNAMES
|
;;; shop::secret-sale reaches the internal ones too. :NICKNAMES
|
||||||
;;; gives a package extra names to call it by. And :SHADOW keeps a
|
;;; gives a package extra names to call it by. And :SHADOW claims a
|
||||||
;;; name a package USEs from colliding with your own - without it,
|
;;; name a USEd package would otherwise lend you: FILL below means
|
||||||
;;; defining FILL below would quietly redefine COMMON-LISP's FILL
|
;;; POST-OFFICE's own symbol, the claim spelled out in the
|
||||||
;;; for everyone.
|
;;; defpackage. Without it, plain FILL inside POST-OFFICE reads as
|
||||||
|
;;; COMMON-LISP's own - the DEFUN below would redefine that for
|
||||||
|
;;; everyone, and SBCL's package lock refuses, with an error.
|
||||||
|
|
||||||
(defpackage #:shop
|
(defpackage #:shop
|
||||||
(:use #:common-lisp)
|
(:use #:common-lisp)
|
||||||
@@ -27,8 +29,9 @@
|
|||||||
(shop:price))
|
(shop:price))
|
||||||
|
|
||||||
;; TODO: The defpackage below is missing its (:shadow #:fill).
|
;; TODO: The defpackage below is missing its (:shadow #:fill).
|
||||||
;; Add it, or DEFUN FILL under POST-OFFICE redefines COMMON-LISP's
|
;; Add it, so POST-OFFICE claims FILL up front - without the claim
|
||||||
;; FILL for everyone.
|
;; the DEFUN below would redefine COMMON-LISP's own FILL, and
|
||||||
|
;; SBCL's package lock refuses to load the file at all.
|
||||||
(defpackage #:post-office
|
(defpackage #:post-office
|
||||||
(:use #:common-lisp))
|
(:use #:common-lisp))
|
||||||
|
|
||||||
@@ -49,3 +52,5 @@
|
|||||||
(check-equal (list 0 0 0) (fill (list 1 2 3) 0))
|
(check-equal (list 0 0 0) (fill (list 1 2 3) 0))
|
||||||
(check-equal '(post-office::stuffed crate)
|
(check-equal '(post-office::stuffed crate)
|
||||||
(funcall (find-symbol "FILL" '#:post-office) 'crate))
|
(funcall (find-symbol "FILL" '#:post-office) 'crate))
|
||||||
|
(check (member "FILL" (package-shadowing-symbols '#:post-office)
|
||||||
|
:test #'string= :key #'symbol-name))
|
||||||
@@ -5,3 +5,6 @@ Classes, instances, generic dispatch, and method combination.
|
|||||||
DEFGENERIC names an operation; DEFMETHOD implements it, once per
|
DEFGENERIC names an operation; DEFMETHOD implements it, once per
|
||||||
class. :BEFORE and :AFTER methods combine around the primary one,
|
class. :BEFORE and :AFTER methods combine around the primary one,
|
||||||
and (EQL x) specializers dispatch on a single value.
|
and (EQL x) specializers dispatch on a single value.
|
||||||
|
WITH-SLOTS and WITH-ACCESSORS read a whole object at a glance,
|
||||||
|
CALL-NEXT-METHOD stands on the method above, and PRINT-OBJECT with
|
||||||
|
:DEFAULT-INITARGS shape how objects print and build.
|
||||||
@@ -29,8 +29,12 @@
|
|||||||
;;; them unchanged.
|
;;; them unchanged.
|
||||||
;;; ------------------------------------------------------------------
|
;;; ------------------------------------------------------------------
|
||||||
|
|
||||||
(check (let ((q (double-point (make-instance 'point :x 3 :y 4))))
|
(check (let* ((p (make-instance 'point :x 3 :y 4))
|
||||||
(and (eql 6 (point-x q)) (eql 8 (point-y q)))))
|
(q (double-point p)))
|
||||||
|
(and (not (eq q p))
|
||||||
|
(eql 3 (point-x p))
|
||||||
|
(eql 6 (point-x q))
|
||||||
|
(eql 8 (point-y q)))))
|
||||||
(check (let ((p (shift-x (make-instance 'point :x 1))))
|
(check (let ((p (shift-x (make-instance 'point :x 1))))
|
||||||
(eql 2 (point-x p))))
|
(eql 2 (point-x p))))
|
||||||
(check (let ((p (shift-x (make-instance 'point :x 10))))
|
(check (let ((p (shift-x (make-instance 'point :x 10))))
|
||||||
|
|||||||
@@ -19,14 +19,23 @@
|
|||||||
|
|
||||||
(defgeneric purr (a))
|
(defgeneric purr (a))
|
||||||
|
|
||||||
|
(defmethod purr ((a animal))
|
||||||
|
"prrr-from-animal")
|
||||||
|
|
||||||
|
(defgeneric hiss (a))
|
||||||
|
|
||||||
;; TODO: A DOG announces what an animal announces, then adds
|
;; TODO: A DOG announces what an animal announces, then adds
|
||||||
;; " Woof!".
|
;; " Woof!".
|
||||||
(defmethod announce ((d dog))
|
(defmethod announce ((d dog))
|
||||||
"Woof!")
|
"Woof!")
|
||||||
|
|
||||||
;; TODO: CAT purrs: if a method above you exists, use its answer;
|
;; TODO: CAT purrs: if a method above you exists, use its answer;
|
||||||
;; otherwise say "Prrr".
|
;; otherwise say "Prrr" - and CAT hisses the same way, though HISS
|
||||||
|
;; has no method above CAT at all.
|
||||||
(defmethod purr ((c cat))
|
(defmethod purr ((c cat))
|
||||||
|
"Prrr")
|
||||||
|
|
||||||
|
(defmethod hiss ((c cat))
|
||||||
(call-next-method))
|
(call-next-method))
|
||||||
|
|
||||||
;;; ------------------------------------------------------------------
|
;;; ------------------------------------------------------------------
|
||||||
@@ -36,4 +45,5 @@
|
|||||||
|
|
||||||
(check-equal "I am an animal. Woof!" (announce (make-instance 'dog)))
|
(check-equal "I am an animal. Woof!" (announce (make-instance 'dog)))
|
||||||
(check-equal "I am an animal." (announce (make-instance 'animal)))
|
(check-equal "I am an animal." (announce (make-instance 'animal)))
|
||||||
(check-equal "Prrr" (purr (make-instance 'cat)))
|
(check-equal "prrr-from-animal" (purr (make-instance 'cat)))
|
||||||
|
(check-equal "Prrr" (hiss (make-instance 'cat)))
|
||||||
@@ -4,4 +4,7 @@ Conditions, handlers, restarts: the crown jewel of Common Lisp.
|
|||||||
|
|
||||||
ERROR signals, HANDLER-CASE catches, UNWIND-PROTECT cleans up.
|
ERROR signals, HANDLER-CASE catches, UNWIND-PROTECT cleans up.
|
||||||
DEFINE-CONDITION makes your own error types, and restarts let the
|
DEFINE-CONDITION makes your own error types, and restarts let the
|
||||||
recovery happen exactly where it makes sense.
|
recovery happen exactly where it makes sense. :REPORT words a
|
||||||
|
condition for humans, WARN and SIGNAL carry on instead of
|
||||||
|
unwinding, restarts can take arguments, and IGNORE-ERRORS swaps an
|
||||||
|
error for NIL.
|
||||||
@@ -46,8 +46,15 @@
|
|||||||
(empty-cart (c) (format nil "~a" c))))
|
(empty-cart (c) (format nil "~a" c))))
|
||||||
(check-equal '(battery 15) (battery-check 15))
|
(check-equal '(battery 15) (battery-check 15))
|
||||||
(check-equal '(battery 90) (battery-check 90))
|
(check-equal '(battery 90) (battery-check 90))
|
||||||
|
(check-equal :noticed (handler-case (battery-check 15)
|
||||||
|
(warning () :noticed)))
|
||||||
(check-equal :noticed (handler-case (warn "battery low")
|
(check-equal :noticed (handler-case (warn "battery low")
|
||||||
(warning () :noticed)))
|
(warning () :noticed)))
|
||||||
(check-equal :swapped (handler-case (check-battery 5)
|
(check-equal :swapped (handler-case (check-battery 5)
|
||||||
(low-battery () :swapped)))
|
(low-battery () :swapped)))
|
||||||
(check-equal '(battery 20) (check-battery 20))
|
(check-equal '(battery 20) (check-battery 20))
|
||||||
|
(check-equal :swapped (handler-case (check-battery 10)
|
||||||
|
(low-battery () :swapped)))
|
||||||
|
(check-equal '(battery 11)
|
||||||
|
(handler-case (check-battery 11)
|
||||||
|
(low-battery () :leaked)))
|
||||||
@@ -4,4 +4,5 @@ DEFMACRO, backquote templates, hygiene with GENSYM.
|
|||||||
|
|
||||||
A macro writes code. The backquote family (` , ,@) makes templates
|
A macro writes code. The backquote family (` , ,@) makes templates
|
||||||
cheap, and GENSYM keeps a macro's own variables from capturing
|
cheap, and GENSYM keeps a macro's own variables from capturing
|
||||||
yours.
|
yours. The reader has macros too: SET-DISPATCH-MACRO-CHARACTER
|
||||||
|
teaches #\ a new trick, so #? can read as code of its own.
|
||||||
@@ -4,4 +4,6 @@ Closures and special variables: two ways a function reaches out.
|
|||||||
|
|
||||||
A closure captures the variables around it. A DEFPARAMETER variable
|
A closure captures the variables around it. A DEFPARAMETER variable
|
||||||
is dynamic: LET rebinding it changes what every called function
|
is dynamic: LET rebinding it changes what every called function
|
||||||
sees, and restores the old value afterwards.
|
sees, and restores the old value afterwards. DEFVAR makes the same
|
||||||
|
kind of variable but keeps quiet on reload - it never overwrites a
|
||||||
|
value that is already there.
|
||||||
@@ -190,7 +190,7 @@ Good luck - and keep a REPL open. That's the Lisp way!")
|
|||||||
:hint "FIND returns the element, POSITION its index, COUNT the matches: (position 'b '(a b c)) => 1. :test decides what matches; the default treats 1 and 1.0 as different, so use (find x xs :test #'=).")
|
:hint "FIND returns the element, POSITION its index, COUNT the matches: (position 'b '(a b c)) => 1. :test decides what matches; the default treats 1 and 1.0 as different, so use (find x xs :test #'=).")
|
||||||
(:name "sequences2"
|
(:name "sequences2"
|
||||||
:dir "19_sequences"
|
:dir "19_sequences"
|
||||||
:hint "REMOVE drops matches: (remove x xs), mind the argument order. REMOVE-IF drops what its predicate accepts. SUBSTITUTE reads (NEW OLD SEQUENCE). EVERY wants the predicate true of all elements; SOME settles for one.")
|
:hint "REMOVE drops matches: (remove x xs), mind the argument order. REMOVE-IF drops what its predicate accepts. SUBSTITUTE reads (NEW OLD SEQUENCE).")
|
||||||
(:name "sequences3"
|
(:name "sequences3"
|
||||||
:dir "19_sequences"
|
:dir "19_sequences"
|
||||||
:hint "SORT takes the comparison first: (sort (list 3 1 2) #'<). With :key it compares one part of each element: (sort pairs #'< :key #'cdr). REVERSE returns a backwards copy - MAPCAR it over each word.")
|
:hint "SORT takes the comparison first: (sort (list 3 1 2) #'<). With :key it compares one part of each element: (sort pairs #'< :key #'cdr). REVERSE returns a backwards copy - MAPCAR it over each word.")
|
||||||
@@ -251,7 +251,7 @@ Good luck - and keep a REPL open. That's the Lisp way!")
|
|||||||
:hint "DO steps every variable with the OLD values, like LET - so TOTAL's step must be (+ total i). DO* steps one at a time like LET*, and B's step (* b a) then sees A's NEW value - swap the factorial's DO for DO* and it multiplies the right pairs.")
|
:hint "DO steps every variable with the OLD values, like LET - so TOTAL's step must be (+ total i). DO* steps one at a time like LET*, and B's step (* b a) then sees A's NEW value - swap the factorial's DO for DO* and it multiplies the right pairs.")
|
||||||
(:name "loops6"
|
(:name "loops6"
|
||||||
:dir "10_loops"
|
:dir "10_loops"
|
||||||
:hint "COUNT wants a test: (loop for x in xs count (oddp x)). MAXIMIZE tracks the biggest: (loop for x in xs maximize x), NIL when the loop never runs. For the wallet LOOP-FINISH bails out before the total goes over: (if (> (+ total x) limit) (loop-finish) (setf total (+ total x))), and FINALLY returns the total either way.")
|
:hint "COUNT wants a test: (loop for x in xs count (oddp x)). MAXIMIZE tracks the biggest: (loop for x in xs maximize x) - but what an empty run answers is implementation-dependent (0 in SBCL), so WIDEST must answer NIL itself when XS is empty. For the wallet LOOP-FINISH bails out before the total goes over: (if (> (+ total x) limit) (loop-finish) (setf total (+ total x))), and FINALLY returns the total either way.")
|
||||||
(:name "num1"
|
(:name "num1"
|
||||||
:dir "11_numbers"
|
:dir "11_numbers"
|
||||||
:hint "Drop the 2.0: (expt 2 100) and (/ 7 2) stay exact when all arguments are integers.")
|
:hint "Drop the 2.0: (expt 2 100) and (/ 7 2) stay exact when all arguments are integers.")
|
||||||
@@ -302,7 +302,7 @@ Good luck - and keep a REPL open. That's the Lisp way!")
|
|||||||
:hint "Name the package: (find-symbol name 'attic) - with no package argument it searches *package* and finds nothing. INTERN makes-or-finds: (intern name 'attic) answers with the symbol either way, so (symbol-name (attic-intern \"SPARE-KEY\")) is \"SPARE-KEY\".")
|
:hint "Name the package: (find-symbol name 'attic) - with no package argument it searches *package* and finds nothing. INTERN makes-or-finds: (intern name 'attic) answers with the symbol either way, so (symbol-name (attic-intern \"SPARE-KEY\")) is \"SPARE-KEY\".")
|
||||||
(:name "pkg5"
|
(:name "pkg5"
|
||||||
:dir "14_packages"
|
:dir "14_packages"
|
||||||
:hint "The double colon reaches internals: shop::secret-sale. For the clash, add (:shadow #:fill) to the defpackage - then FILL inside POST-OFFICE means POST-OFFICE's own, and COMMON-LISP's FILL still fills sequences, which the third check relies on. The nickname STORE reaches SHOP the single-colon way.")
|
:hint "The double colon reaches internals: shop::secret-sale. Add (:shadow #:fill) to the defpackage: POST-OFFICE claims FILL as its own symbol up front, and the DEFUN below defines that one. Without the claim, plain FILL inside POST-OFFICE reads as COMMON-LISP's, and SBCL's package lock stops the file from loading. CL:FILL itself stays untouched - the third check still calls it from CL-USER. The nickname STORE reaches SHOP the single-colon way.")
|
||||||
(:name "clos1"
|
(:name "clos1"
|
||||||
:dir "15_clos"
|
:dir "15_clos"
|
||||||
:hint "MAKE-INSTANCE with initargs: (make-instance 'dog :name \"Rex\" :tricks '(\"sit\" \"roll-over\")). Initargs are keywords named after the slots.")
|
:hint "MAKE-INSTANCE with initargs: (make-instance 'dog :name \"Rex\" :tricks '(\"sit\" \"roll-over\")). Initargs are keywords named after the slots.")
|
||||||
|
|||||||
@@ -39,3 +39,5 @@
|
|||||||
(check-equal (list 0 0 0) (fill (list 1 2 3) 0))
|
(check-equal (list 0 0 0) (fill (list 1 2 3) 0))
|
||||||
(check-equal '(post-office::stuffed crate)
|
(check-equal '(post-office::stuffed crate)
|
||||||
(funcall (find-symbol "FILL" '#:post-office) 'crate))
|
(funcall (find-symbol "FILL" '#:post-office) 'crate))
|
||||||
|
(check (member "FILL" (package-shadowing-symbols '#:post-office)
|
||||||
|
:test #'string= :key #'symbol-name))
|
||||||
@@ -18,8 +18,12 @@
|
|||||||
;;; them unchanged.
|
;;; them unchanged.
|
||||||
;;; ------------------------------------------------------------------
|
;;; ------------------------------------------------------------------
|
||||||
|
|
||||||
(check (let ((q (double-point (make-instance 'point :x 3 :y 4))))
|
(check (let* ((p (make-instance 'point :x 3 :y 4))
|
||||||
(and (eql 6 (point-x q)) (eql 8 (point-y q)))))
|
(q (double-point p)))
|
||||||
|
(and (not (eq q p))
|
||||||
|
(eql 3 (point-x p))
|
||||||
|
(eql 6 (point-x q))
|
||||||
|
(eql 8 (point-y q)))))
|
||||||
(check (let ((p (shift-x (make-instance 'point :x 1))))
|
(check (let ((p (shift-x (make-instance 'point :x 1))))
|
||||||
(eql 2 (point-x p))))
|
(eql 2 (point-x p))))
|
||||||
(check (let ((p (shift-x (make-instance 'point :x 10))))
|
(check (let ((p (shift-x (make-instance 'point :x 10))))
|
||||||
|
|||||||
@@ -11,6 +11,11 @@
|
|||||||
|
|
||||||
(defgeneric purr (a))
|
(defgeneric purr (a))
|
||||||
|
|
||||||
|
(defmethod purr ((a animal))
|
||||||
|
"prrr-from-animal")
|
||||||
|
|
||||||
|
(defgeneric hiss (a))
|
||||||
|
|
||||||
(defmethod announce ((d dog))
|
(defmethod announce ((d dog))
|
||||||
(concatenate 'string (call-next-method) " Woof!"))
|
(concatenate 'string (call-next-method) " Woof!"))
|
||||||
|
|
||||||
@@ -19,6 +24,11 @@
|
|||||||
(call-next-method)
|
(call-next-method)
|
||||||
"Prrr"))
|
"Prrr"))
|
||||||
|
|
||||||
|
(defmethod hiss ((c cat))
|
||||||
|
(if (next-method-p)
|
||||||
|
(call-next-method)
|
||||||
|
"Prrr"))
|
||||||
|
|
||||||
;;; ------------------------------------------------------------------
|
;;; ------------------------------------------------------------------
|
||||||
;;; Checks. Read them - they tell you what to aim for - but leave
|
;;; Checks. Read them - they tell you what to aim for - but leave
|
||||||
;;; them unchanged.
|
;;; them unchanged.
|
||||||
@@ -26,4 +36,5 @@
|
|||||||
|
|
||||||
(check-equal "I am an animal. Woof!" (announce (make-instance 'dog)))
|
(check-equal "I am an animal. Woof!" (announce (make-instance 'dog)))
|
||||||
(check-equal "I am an animal." (announce (make-instance 'animal)))
|
(check-equal "I am an animal." (announce (make-instance 'animal)))
|
||||||
(check-equal "Prrr" (purr (make-instance 'cat)))
|
(check-equal "prrr-from-animal" (purr (make-instance 'cat)))
|
||||||
|
(check-equal "Prrr" (hiss (make-instance 'cat)))
|
||||||
@@ -33,8 +33,15 @@
|
|||||||
(empty-cart (c) (format nil "~a" c))))
|
(empty-cart (c) (format nil "~a" c))))
|
||||||
(check-equal '(battery 15) (battery-check 15))
|
(check-equal '(battery 15) (battery-check 15))
|
||||||
(check-equal '(battery 90) (battery-check 90))
|
(check-equal '(battery 90) (battery-check 90))
|
||||||
|
(check-equal :noticed (handler-case (battery-check 15)
|
||||||
|
(warning () :noticed)))
|
||||||
(check-equal :noticed (handler-case (warn "battery low")
|
(check-equal :noticed (handler-case (warn "battery low")
|
||||||
(warning () :noticed)))
|
(warning () :noticed)))
|
||||||
(check-equal :swapped (handler-case (check-battery 5)
|
(check-equal :swapped (handler-case (check-battery 5)
|
||||||
(low-battery () :swapped)))
|
(low-battery () :swapped)))
|
||||||
(check-equal '(battery 20) (check-battery 20))
|
(check-equal '(battery 20) (check-battery 20))
|
||||||
|
(check-equal :swapped (handler-case (check-battery 10)
|
||||||
|
(low-battery () :swapped)))
|
||||||
|
(check-equal '(battery 11)
|
||||||
|
(handler-case (check-battery 11)
|
||||||
|
(low-battery () :leaked)))
|
||||||
Reference in new issue
Block a user