This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

Establishing a condition handler at the REPL

3 posts · 4108 views

Is it possible to establish a condition handler at the REPL in such a way that it can handle conditions that occur at the REPL?

So, for example, if I were sitting at my SLIME prompt, and I tried to evaluate
CL-USER> (foo)
where #'foo was not bound, I'd like to be able to effectively handle it by calling (bar 'foo).

I think the answer is no, you'd have to establish the handler in an enclosing form.

I assume you could establish such a handler from SLIME; is there another way?
~garethw

Re: Establishing a condition handler at the REPL

garethw wrote:Is it possible to establish a condition handler at the REPL in such a way that it can handle conditions that occur at the REPL?
Only if the condition handler is established before the REPL is started. For example, some Common Lisp implementations provide command-line arguments or implementation-specific hooks for customizing the Common Lisp REPL.

AFAIK the only semi-portable way to customize the error handling from the REPL is making the Common Lisp *DEBUGGER-HOOK* point to a function that is run before the implementation-specific debugger is entered. This way the Slime debugger is hooked into Common Lisp. But to replace UNDEFINED-FUNCTION conditions with your own function via the *DEBUGGER-HOOK* without entering the implementation-specific debugger afterwards, your Common Lisp implementation needs to provide a USE-VALUE restart for the UNDEFINED-FUNCTION condition, what not all implementations do.

I'm writing "semi-portable" because the debugger behaviour is entirely implementation-defined. To support multiple implementations you probably would need to write and maintain #+ and #- implementation-specific code.

AFAIK the only other alternative is to write your own REPL enclosed with appropriate condition handlers and run it inside the Common Lisp REPL.

- edgar

Re: Establishing a condition handler at the REPL

Though since the REPL will be a function inside one of the implementation defined packages, this isn't generally that hard :)