Escalating multi-paragraph hints (wave 3, F2)

info.sexp :hint now accepts a string or a list of paragraph strings; normalize-hint converts entries at load and fails fast on malformed ones (lisplings: Bad :hint for <name> ...).

In watch mode h reveals one paragraph per press and revealed hints stay
pinned on the screen, resetting when the exercise changes; hint
[name] prints every paragraph numbered. intro1, functions3 and quiz1
are converted to paragraph lists as examples; every other entry keeps
working as a plain string.
This commit is contained in:
venomade committed 2026-11-22 09:53:37 +00:00
1 parent 516b256ea3
commit 04e313a915
3 files changed
+40 -20

No files matched your search

+2 -2
View File
@@ -62,7 +62,7 @@ Keys in watch mode (each key is a line: type it, then press ENTER):
| key | action |
| --- | ------------------------------------ |
| n | move to the next pending exercise |
| h | show the hint, pinned on the screen |
| h | reveal the next hint paragraph (stays pinned) |
| r | rerun the current exercise |
| l | list all exercises |
| q | save progress and quit |
@@ -78,7 +78,7 @@ solved.
```sh
./lisplings watch the current exercise (the default)
./lisplings run [name] run one exercise and print its output
./lisplings hint [name] show the hint for an exercise
./lisplings hint [name] print every hint paragraph, numbered
./lisplings list [pending|done|all]
./lisplings reset <name> restore an exercise to its pristine state
./lisplings check-all run every exercise and resync progress
+8 -4
View File
@@ -3,7 +3,8 @@
;;; Read by the lisplings runner. Each exercise is a plist:
;;; :name the exercise name; file is exercises/<dir>/<name>.lisp
;;; :dir the chapter directory
;;; :hint shown by `lisplings hint <name>'
;;; :hint one hint paragraph, or a list of them; watch mode reveals
;;; one per `h', `lisplings hint <name>' prints them all
((:welcome "Welcome to Lisplings!
@@ -30,7 +31,7 @@ Found an issue, or want to add an exercise? Improvements welcome!")
(:exercises
((:name "intro1"
:dir "00_intro"
:hint "This exercise has no errors. Play with the banner, save the file, and press n in the terminal. You might need to press ENTER after typing n.")
:hint ("This exercise has no errors. Play with the banner, save the file, and press n in the terminal. You might need to press ENTER after typing n."))
(:name "intro2"
:dir "00_intro"
:hint "The format directive ~a expects a value from the arguments after the format string. The string below has no arguments at all...")
@@ -51,7 +52,9 @@ Found an issue, or want to add an exercise? Improvements welcome!")
:hint "Match the parameter list to the calls: average is called with TWO numbers here. And (- a b) subtracts b from a - check which way round you wrote it.")
(:name "functions3"
:dir "02_functions"
:hint "&OPTIONAL gives a parameter a default: (defun repeat-word (word &optional (n 2)) ...). For the box, a keyword default may use an earlier parameter: (defun make-box (width &key (height width) (depth width)) ...).")
:hint ("&OPTIONAL gives a parameter a default: (defun repeat-word (word &optional (n 2)) ...)."
"A keyword default may use an earlier parameter: (defun make-box (width &key (height width) (depth width)) ...)."
"Further reading: CLHS 3.4.1 (ordinary lambda lists) and PCL ch. 5, https://gigamonkeys.com/book/functions.html"))
(:name "functions4"
:dir "02_functions"
:hint "FLOOR returns two values at once: (floor 10 3) is 3 and 1. Pass it straight through. For 125 seconds: (floor seconds 60) is 2 minutes and 5 seconds.")
@@ -234,7 +237,8 @@ Found an issue, or want to add an exercise? Improvements welcome!")
:hint "MULTIPLE-VALUE-BIND on GETHASH: if PRESENT return the value, otherwise compute, SETF the table, return. The second call must not touch SLOW-FIB again.")
(:name "quiz1"
:dir "quizzes"
:hint "APPEND makes a new book with the contact at the end. DOLIST + STRING-EQUAL + GETF finds by name; FORMAT makes the card.")
:hint ("APPEND makes a new book with the contact at the end."
"DOLIST + STRING-EQUAL + GETF finds by name; FORMAT makes the card."))
(:name "quiz2"
:dir "quizzes"
:hint "A COND over three shapes: numbers, quote forms, and operator forms. MEMBER (car expr) '(+ - *) recognizes the operators; APPLY + MAPCAR evaluates the arguments."))))
+30 -14
View File
@@ -65,6 +65,16 @@
;; terminal; tell it whether the parent is showing color.
(sb-posix:setenv "LISPLINGS_COLOR" (if *use-color* "always" "never") 1))
(defun normalize-hint (raw name)
"Normalize a :hint catalogue entry to a list of paragraph strings.
A single string becomes a one-element list, a list of strings passes
through, anything else fails fast at startup."
(cond ((null raw) '())
((stringp raw) (list raw))
((and (listp raw) (every #'stringp raw)) (copy-list raw))
(t (error "Bad :hint for ~a: expected a string or list of strings"
name))))
(defun make-exercises ()
(mapcar (lambda (spec)
(let ((name (getf spec :name))
@@ -72,7 +82,7 @@
(make-exercise
:name name
:dir dir
:hint (getf spec :hint)
:hint (normalize-hint (getf spec :hint) name)
:done (and (member name (getf *state* :done) :test #'string=) t)
:path (merge-pathnames (format nil "exercises/~a/~a.lisp" dir name)
*project*)
@@ -283,17 +293,24 @@ Returns (values output-string exit-code timed-out-p)."
(nth (screen-state-index state) *exercises*))
(defun hint-paragraphs (ex)
"The hint as a list of paragraph strings. The catalogue gives either
a plain string or a list of strings."
(let ((hint (exercise-hint ex)))
(cond ((null hint) '())
((stringp hint) (list hint))
((and (listp hint) (every #'stringp hint)) hint)
(t (error "Bad :hint for ~a: expected a string or list of strings"
(exercise-name ex))))))
"The hint paragraphs; make-exercises normalizes :hint to a list."
(exercise-hint ex))
(defun hint-count (ex)
(length (hint-paragraphs ex)))
(length (exercise-hint ex)))
(defun reveal-next-hint (state)
"Reveal one more hint paragraph for the current exercise, or
explain why that is not possible."
(let ((total (hint-count (current-exercise state))))
(cond ((zerop total)
(setf (screen-state-notice state)
"No hint for this one. You're on your own!"))
((< (screen-state-revealed state) total)
(incf (screen-state-revealed state)))
(t
(setf (screen-state-notice state)
"No more hints for this exercise.")))))
(defun valid-keys (state)
"The keys that make sense right now, as key-and-label strings."
@@ -519,10 +536,9 @@ the queue. Returns NIL at EOF."
(t
(setf (screen-state-result state) :alldone)
(render-screen state))))))))
((string-equal cmd "h")
(setf (screen-state-revealed state)
(hint-count (current-exercise state)))
(render-screen state))
((string-equal cmd "h")
(reveal-next-hint state)
(render-screen state))
((or (string-equal cmd "r") (string= cmd ""))
(run-and-show state queue lock))
((string-equal cmd "l")