Fix 16 mid-chapter exercise defects (scouts mid1+mid2)

Verified: dev/verify.sh all 70 exercises green (broken fail, solved pass).
This commit is contained in:
venomade committed 2026-11-22 04:52:35 +00:00
1 parent 2735c8dca5
commit 6e2c382c78
24 files changed
+34 -15

No files matched your search

+1
View File
@@ -20,3 +20,4 @@
(check-equal "hot" (classify 35))
(check-equal "pleasant" (classify 20))
(check-equal "hot" (classify 31))
(check-equal "pleasant" (classify 30))
+1
View File
@@ -21,5 +21,6 @@
(check-equal nil (only-positive-squares -3))
(check-equal 9 (only-positive-squares 3))
(check-equal nil (only-positive-squares 0))
(check-equal :welcome (enter t))
(check-equal :denied (enter nil))
+2
View File
@@ -16,3 +16,5 @@
(check (truthy-p ""))
(check (not (truthy-p nil)))
(check (not (truthy-p '())))
(check-equal t (truthy-p 0))
(check-equal nil (truthy-p nil))
+1
View File
@@ -22,3 +22,4 @@
(check-equal :string (describe-value "hi"))
(check-equal :list (describe-value '(a b)))
(check-equal :nothing (describe-value nil))
(check-equal :other (describe-value 'hi))
+2 -2
View File
@@ -25,5 +25,5 @@
(check-equal 2 (price 'tea))
(check-equal nil (price 'chai))
(check (let ((menu (add-item 'chai 5)))
(and (eql 5 (price 'chai))
(eql 3 (price 'coffee)))))
(and (eql 5 (cdr (assoc 'chai menu)))
(eql 3 (cdr (assoc 'coffee menu))))))
+1
View File
@@ -1,5 +1,6 @@
;;; RECURSION 4: WALKING A TREE
;;;
;;; ATOM is T for anything that is not a cons cell.
;;; Lists nest, and a tree has TWO recursive parts: the first
;;; element and the rest. Recurse into both.
+2
View File
@@ -3,6 +3,8 @@
;;; MAPCAR applies a function to each element and collects the
;;; results into a new list:
;;; (mapcar #'1+ '(1 2 3)) => (2 3 4)
;;; Uppercase a string with STRING-UPCASE: (string-upcase "ada")
;;; => "ADA" (chapter 09 digs in).
;; TODO: Every element of XS, doubled.
(defun double-all (xs)
+1
View File
@@ -3,6 +3,7 @@
;;; FUNCALL spells the arguments out; APPLY takes the last of them
;;; from a list:
;;; (apply #'+ 1 2 '(3 4)) => 10
;;; MAX returns the largest of its arguments: (max 1 5 2) => 5
;; TODO: Add up all of XS, using APPLY.
(defun sum-of (xs)
+1
View File
@@ -19,6 +19,7 @@
(check-equal 4 (biggest '(3 1 4)))
(check-equal 2 (biggest '(2)))
(check-equal 9 (biggest '(1 9 2)))
(check-equal 6 (product '(1 2 3)))
(check-equal 7 (product '(7)))
(check-equal 1 (product '()))
+3 -3
View File
@@ -1,8 +1,8 @@
;;; STRINGS 1: FORMAT DIRECTIVES
;;;
;;; FORMAT is a little language: ~a prints readably, ~10a pads to a
;;; width, ~% is a newline. The first argument NIL means "return a
;;; string" instead of printing.
;;; FORMAT is a little language: ~a prints a value plainly; ~s
;;; prints it readably. ~10a pads to a width, ~% is a newline. The
;;; first argument NIL means "return a string" instead of printing.
;;; (format nil "Hello, ~a!" "Ada") => "Hello, Ada!"
;; TODO: "Ada has 42 cats." with the name and count in place.
+1
View File
@@ -20,6 +20,7 @@
(check-equal 10 (floor-to-five 12))
(check-equal 10 (floor-to-five 14))
(check-equal 15 (floor-to-five 15))
(check-equal -15 (floor-to-five -12))
(check-equal 4 (mod-five 9))
(check-equal 0 (mod-five -5))
(check-equal 1 (mod-five -9))
+1 -1
View File
@@ -2,7 +2,7 @@
;;;
;;; DEFSTRUCT defines a record type and generates, for free:
;;; a constructor (make-person), slot readers (person-name),
;;; and a predicate (personp).
;;; and a predicate (person-p).
(defstruct person
name
+2 -2
View File
@@ -19,9 +19,9 @@
;;; them unchanged.
;;; ------------------------------------------------------------------
(check (let ((c (make-counter)))
(check (let ((c (make-counter :value 9)))
(bump c)
(eql 1 (counter-value c))))
(eql 10 (counter-value c))))
(check (let ((c (make-counter :value 9)))
(reset-counter c)
(eql 0 (counter-value c))))
+1
View File
@@ -3,6 +3,7 @@
;;; The classic hash-table job: tally. GETHASH takes a default:
;;; (gethash x table 0)
;;; so a missing key counts as 0 and INCF can do the rest.
;;; (hash-table-count table) is the number of stored keys.
;; TODO: Count the occurrences of each element of XS. Return the
;;; table.