fosskers's Blog

fosskers's Avatar Image
Haskell -> Rust -> Lisps
← All posts

So, it turns out that ABCL doesn’t support resuming from arbitrary stack frames, but it does support restarts in general. For example:

(defun prompt-new-value (prompt)
  (format *query-io* prompt)
  (force-output *query-io*)
  (list (read *query-io*)))

(defun high ()
  (format t "High~%")
  (middle '(1 2 3 4 5 6)))

(defun middle (items)
  (format t "Middle~%")
  (loop for item in items
        do (low item)))

(defun low (item)
  (if (= item 4)
      (restart-case (error "Oh my god, a 4.")
        (use-value (value)
          :report "Anything but a 4!"
          :interactive (lambda () (prompt-new-value "Number: "))
          (low value)))
      (format t "~A~%" item)))

calling (high) and interactively passing a 9 to the restart yields:

High
Middle
1
2
3
9
5
6

#commonlisp

To like or reply, open original post on Emacs.ch