Wave 4: add sequences/vectors/files chapters, 23 exercises, quiz3, finish ceremony, PCL table

This commit is contained in:
venomade committed 2026-11-22 11:15:35 +00:00
1 parent 77843402fa
commit 4675bd1106
76 files changed
+2505 -14

No files matched your search

+40
View File
@@ -0,0 +1,40 @@
;;; CONDITIONS 5: REPORTS, WARN, SIGNAL (solution)
(define-condition low-battery (condition) ())
(define-condition empty-cart (error)
()
(:report "The cart is empty - nothing to check out."))
(defun checkout (items)
(when (null items)
(error 'empty-cart))
(list 'order items))
(defun battery-check (percent)
(when (< percent 20)
(warn "battery ~a%!" percent))
(list 'battery percent))
(defun check-battery (percent)
(when (<= percent 10)
(signal 'low-battery))
(list 'battery percent))
;;; ------------------------------------------------------------------
;;; Checks. Read them - they tell you what to aim for - but leave
;;; them unchanged.
;;; ------------------------------------------------------------------
(check-equal '(order (milk)) (checkout '(milk)))
(check-error (checkout '()) 'empty-cart)
(check-equal "The cart is empty - nothing to check out."
(handler-case (checkout '())
(empty-cart (c) (format nil "~a" c))))
(check-equal '(battery 15) (battery-check 15))
(check-equal '(battery 90) (battery-check 90))
(check-equal :noticed (handler-case (warn "battery low")
(warning () :noticed)))
(check-equal :swapped (handler-case (check-battery 5)
(low-battery () :swapped)))
(check-equal '(battery 20) (check-battery 20))