Establishing a condition handler at the REPL

Discussion of Common Lisp
Post Reply
garethw
Posts: 43
Joined: Fri Jul 13, 2012 12:56 pm
Location: Ottawa, ON

Establishing a condition handler at the REPL

Post by garethw » Thu May 14, 2015 2:09 pm

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?
~garethw

edgar-rft
Posts: 226
Joined: Fri Aug 06, 2010 6:34 am
Location: Germany

Re: Establishing a condition handler at the REPL

Post by edgar-rft » Fri May 15, 2015 5:09 pm

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

pjstirling
Posts: 166
Joined: Sun Nov 28, 2010 4:21 pm

Re: Establishing a condition handler at the REPL

Post by pjstirling » Sun May 17, 2015 8:06 am

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

Post Reply