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

+17
View File
@@ -0,0 +1,17 @@
;;; STRINGS 5: NUMBERS IN FORMAT (solution)
(defun price-tag (n)
(format nil "~:d widgets" n))
(defun fixed (label n)
(format nil "~a is about ~,2f" label n))
;;; ------------------------------------------------------------------
;;; Checks. Read them - they tell you what to aim for - but leave
;;; them unchanged.
;;; ------------------------------------------------------------------
(check-equal "1,234,567 widgets" (price-tag 1234567))
(check-equal "7 widgets" (price-tag 7))
(check-equal "pi is about 3.14" (fixed "pi" pi))
(check-equal "e is about 2.72" (fixed "e" 2.718281828))
+19
View File
@@ -0,0 +1,19 @@
;;; STRINGS 6: FORMAT PICKS AND CASE (solution)
(defun tick-tock (n)
(format nil "~[tick~;tock~]" (mod n 2)))
(defun quiet-title (s)
(format nil "~(~a~)" s))
;;; ------------------------------------------------------------------
;;; Checks. Read them - they tell you what to aim for - but leave
;;; them unchanged.
;;; ------------------------------------------------------------------
(check-equal "tick" (tick-tock 0))
(check-equal "tock" (tick-tock 1))
(check-equal "tick" (tick-tock 2))
(check-equal "tock" (tick-tock 5))
(check-equal "grace" (quiet-title "GRACE"))
(check-equal "ada lovelace" (quiet-title "ADA LOVELACE"))
+22
View File
@@ -0,0 +1,22 @@
;;; STRINGS 7: NEWLINES AND COLUMNS (solution)
(defun add-line (s)
(format nil "~&~a" s))
(defun right-column (name width)
(format nil "~v@a" width name))
(defun receipt (item price)
(format nil "~8a~4@a" item price))
;;; ------------------------------------------------------------------
;;; Checks. Read them - they tell you what to aim for - but leave
;;; them unchanged.
;;; ------------------------------------------------------------------
(check-equal "hi" (add-line "hi"))
(check-equal "parrot" (add-line "parrot"))
(check-equal " ada" (right-column "ada" 6))
(check-equal "hi" (right-column "hi" 2))
(check-equal "tea 2" (receipt "tea" 2))
(check-equal "coffee 3" (receipt "coffee" 3))