clisp -on-error abort

Discussion of Common Lisp
Post Reply
White_Owl
Posts: 15
Joined: Wed Sep 13, 2017 2:49 pm

clisp -on-error abort

Post by White_Owl » Wed Sep 13, 2017 3:08 pm

I guess, I should start with: I do not use debuggers. At all. Please lets not discuss this.

From command line I can start clisp with a key "-on-error abort" and in case of error, the REPL will just print an error which I can read and fix.
To type the key in command line all the times is tiresome and I want to set this mode in $HOME/.clisprc.lisp.
How to do it?

I found this page: https://clisp.sourceforge.io/impnotes/r ... al-handler
But I guess I do not understand how to read it.
It looks like I need to call a macro EXT:ABORT-ON-ERROR, but when I do it:

Code: Select all

[1]> (EXT:abort-on-error )
NIL
[2]>
And debugger is not disabled.

Documentation also mentions that the macro supposed to have some parameter form, but what is it?

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

Re: clisp -on-error abort

Post by pjstirling » Fri Sep 15, 2017 9:58 am

EXT:ABORT-ON-ERROR and EXT:EXIT-ON-ERROR are not what you want, probably.

They act as PROGNs that execute a particular RESTART when code SIGNALs at runtime.

So if you have a buffer with code, then if you wrap all of it with an EXT:EXIT-ON-ERROR then clisp will exit if something goes wrong.

They don't change the default policy outside the dynamic extent of their forms.

The usual way to avoid typing extra parameters to a program is to use a shell alias or a shell script

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

Re: clisp -on-error abort

Post by pjstirling » Fri Sep 15, 2017 10:05 am

As an example here is the script I use to connect a terminal to emacs on another machine

Code: Select all

#!/bin/sh
ssh -t $1 emacsclient -nw
(I named it emacsc for quick access)

White_Owl
Posts: 15
Joined: Wed Sep 13, 2017 2:49 pm

Re: clisp -on-error abort

Post by White_Owl » Fri Sep 15, 2017 12:27 pm

pjstirling wrote:EXT:ABORT-ON-ERROR and EXT:EXIT-ON-ERROR are not what you want, probably.

They act as PROGNs that execute a particular RESTART when code SIGNALs at runtime.

So if you have a buffer with code, then if you wrap all of it with an EXT:EXIT-ON-ERROR then clisp will exit if something goes wrong.
hmmm...

Code: Select all

[14]> (EXT:ABORT-ON-ERROR (some-erronous-code))
*** - EVAL: undefined function SOME-ERRONOUS-CODE

[15]>
Ok, I see now. ... probably.

Well, I found the code of function SYS::BREAK (file condition.lisp, lines 1551-1573). If I am not mistaken, that is the main procedure which is called when clisp finds an error. At least I see there formatting of error message and the main debugger's loop.
So if I am correct, I need to redefine *break-driver*? Not sure to what. All attempts so far resulted with "*** - Program stack overflow. RESET" message. And I cannot find documentation for that variable.
pjstirling wrote:The usual way to avoid typing extra parameters to a program is to use a shell alias or a shell script
That is true. But I want to learn 'the lisp way'. The shell approach is too well known, no fun at all :)

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

Re: clisp -on-error abort

Post by pjstirling » Sat Sep 16, 2017 9:37 am

The clisp documentation page you linked tells you how to do it:
Function EXT:SET-GLOBAL-HANDLER. The function (EXT:SET-GLOBAL-HANDLER condition handler) establishes a global handler for the condition. The handler should be FUNCALLable (a SYMBOL or a FUNCTION). If it returns, the next applicable handler is invoked, so if you do not want to land in the debugger, it should not return. E.g., the option -on-error abort and the macro EXT:ABORT-ON-ERROR are implemented by installing the following handler:

(defun sys::abortonerror (condition)
(sys::report-error condition)
(INVOKE-RESTART (FIND-RESTART 'ABORT condition)))
so something like (untested):

Code: Select all

(ext:set-global-handler 'condition
			(lambda (c) (invoke-restart (find-restart 'abort c))))

Post Reply