| Error handling in Dylan[1] worked mostly the same way, if syntax is truly the issue. I posted a toy implementation in Lua a few years ago as well[2]. In general there’s nothing Lisp-specific about the idea, you just need dynamic scoping, closures that don’t outlive their parents, and a way to unwind the stack. Standard exception handling is: - Whenever an error happens, the program puts a description of it into an “exception” object. You go from the innermost dynamic scope to the outermost looking for handlers. Once you find a handler willing to accept that type of exception, you unwind to the point where it was installed then invoke it, passing the exception object. Condition handling[3] is: - Whenever an error happens, the program puts a description of it into a “condition” object. You go from the innermost dynamic scope to the outermost looking for handlers. Once you find a condition handler willing to accept that type of condition, you invoke it as a regular callback, without unwinding, passing the condition object. - The handler then packs up some data into a “restart” object. You go through all the dynamic scopes again (remember that the erroring function is still active). Once you find a restart handling willing to accept this type of restart, you unwind to the point where it was installed then invoke it, passing the restart object. (I am omitting things outside the happy path: a way for the exception/condition handler to punt, what happens if the condition handler does not invoke a restart, etc.) As far as the benefits of this two-phase approach, Practical Common Lisp gives an example[4] of a single-record parser that raises an “invalid record” condition, a loop around it that installs a “skip to next record” restart, and finally the caller can make the policy decision on what to do for invalid records. As another example, Common Lisp signals an “unbound-variable”[5] condition leaving the “use-value” and “store-value” restarts in scope, then the REPL installs a handler that offers them interactively. (My own half-serious example of a DOS abort/retry/fail prompt is in this vein too, chosen mostly because it feels strange that you can’t do it in a conventional exception system.) [1] https://package.opendylan.org/dylan-programming-book/excepti... [2] https://news.ycombinator.com/item?id=31196046 [3] https://www.nhplace.com/kent/Papers/Condition-Handling-2001.... [4] https://gigamonkeys.com/book/beyond-exception-handling-condi... [5] https://www.lispworks.com/documentation/HyperSpec/Body/e_unb... |