Apress / common-lisp-condition-system

Source Code for 'The Common Lisp Condition System' by Michal "phoe" Herda
Other
97 stars 10 forks source link

Various typos in the book #8

Open ANDRON94 opened 3 years ago

ANDRON94 commented 3 years ago

Condition system Errata

2.5.1 Restarts that perform a non-local exit

Text in book(at the end of chapter)

..., among other things, 
disestablish the original restart that we bind via `handler-bind` and to... 
;; COMMENT: I assume it should be `restart-bind`

2.9.6 Recursive debugger

Code

...
(with-simple-restart
    (abort "Return to level ~D of the debugger." current-debugger-level)
  (invoke-restart-interactively (nth chosen-restart restarts))))
(debugger condition hook))))

Output in book

;; Debugger level 2 entered on SIMPLE-ERROR:
;; About to supply "some string".
;;
;; Available restarts:
;; 0 [CONTINUE] Continue.
;; 1 [ABORT] Return to level 1 of the debugger.
;; 2 [RETRY] Retry evaluating the form.
;; 3 [ABORT] Return to the toplevel.
;;
;; Invoke restart number: 1                                    ; user input here
;;
;; Debugger level 1 entered on SIMPLE-TYPE-ERROR:              ;; COMMENT: < HERE!!!
;; The value of X is 42, which is not of type STRING.
;;
;; Available restarts:
;; 0 [STORE-VALUE] Supply a new value for X.
;; 1 [RETRY] Retry evaluating the form.

Actual output

COMMENT: There is no code for decreasing `*debugger-level*` variable before entering `debugger` function recursively.

;; Debugger level 2 entered on SIMPLE-ERROR:
;; About to suply 24.
;;
;; Available restarts: 
;; 0 [CONTINUE] Continue.
;; 1 [ABORT] Return to level 1 of the debugger.
;; 2 [RETRY] Retry SLY mREPL evaluation request.
;; 3 [ABORT] Return to SLY's top level.
;; 4 [ABORT] abort thread
             (#<THREAD "sly-channel-1-mrepl-remote-1" RUNNING {1001FB4A93}>)
;;
;; Invoke restart number: 1
;;
;; Debugger level 2 entered on SIMPLE-TYPE-ERROR:            ;; COMMENT: < HERE!!!
;; The value of X is 42, which is not of type STRING.
;;
;; Available restarts: 
;; 0 [STORE-VALUE] Supply a new value for X.
;; 1 [RETRY] Retry SLY mREPL evaluation request.

2.9.9 Associating conditions with restarts

Text in book

This association is always established by `with-simple-restart` and...
;; COMMENT: Below this text, a couple of times mentioned `handler-case` instead of `restart-case`.

3.6.4 Fourth iteration: Associating conditions with restarts

Text in book

... will be related to the `expression` that is passed to `handler-case`
;; COMMENT: `handler-case` should be replaced with `restart-case`.

4.6.4 Generating data: Python-like generators

Code

(handler-bind ((generated (lambda (,e)
                            (let ((,item (generated-item ,e)))
                              (loop ,@body) ;; COMMENT: Infinite loop here, 'invoke-restart' has no chance to be executed.
                            (invoke-restart (find-restart 'resume))))))
  ,generator-form)
....
....
(let ((foo '(1 2 3)))
  (doing (item (yield (pop foo))))
    (print item)
    (when (emptyp foo) (return)))

Code from vseloved repository

(defmacro doing ((item generator-form &optional result) &body body)
  "Like DOLIST but for iterating GENERATOR-FORM."
  (with-gensyms (e)
    `(block nil
       (handler-bind ((generated (lambda (,e)
                                   (let ((,item (generated-item ,e)))
                                     ,@body ;; COMMENT: No loop here.
                                     (invoke-restart (find-restart 'resume))))))
         ,generator-form)
       ,result)))
phoe commented 3 years ago

Thank you for the fixes! I'll integrate them into an errata in due time.