Lisplings: Rustlings-style exercises for Common Lisp
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.
This commit is contained in:
commit
4df60ead93
172 files changed
+4403
No files matched your search
@@ -0,0 +1,26 @@
|
||||
;;; CONDITIONS 3: YOUR OWN CONDITION TYPES
|
||||
;;;
|
||||
;;; Conditions are classes. DEFINE-CONDITION defines new ones with
|
||||
;;; :INITARGs; ERROR signals them; HANDLER-CASE catches by type.
|
||||
|
||||
(define-condition empty-plate (error)
|
||||
((what :initarg :what :reader empty-plate-what))
|
||||
(:documentation "Signaled when a plate turns out to be empty."))
|
||||
|
||||
;; TODO: eat returns "yum" - unless XS is NIL, when it signals
|
||||
;;; empty-plate with :what "soup".
|
||||
(defun eat (xs)
|
||||
"yum")
|
||||
|
||||
;; TODO: catch-empty calls (eat xs); when the plate is empty it
|
||||
;;; returns the condition's WHAT instead.
|
||||
(defun catch-empty (xs)
|
||||
(eat xs))
|
||||
|
||||
;;; ------------------------------------------------------------------
|
||||
;;; Checks. Read them - they tell you what to aim for - but leave
|
||||
;;; them unchanged.
|
||||
;;; ------------------------------------------------------------------
|
||||
|
||||
(check-equal "yum" (catch-empty '(a b)))
|
||||
(check-equal "soup" (catch-empty '()))
|
||||
Reference in new issue
Block a user