Page 1 of 1

Establishing a condition handler at the REPL

Posted: Thu May 14, 2015 2:09 pm
by garethw
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

Code: Select all

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?

Re: Establishing a condition handler at the REPL

Posted: Fri May 15, 2015 5:09 pm
by edgar-rft
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

Posted: Sun May 17, 2015 8:06 am
by pjstirling
Though since the REPL will be a function inside one of the implementation defined packages, this isn't generally that hard :)