how to turn off the debugger in sbcl
Asked Answered
A

2

14

I'm trying to learn common lisp currently and I've been using sbcl (I hope that's a decent implementation choice.)

Coming from ruby and irb I find the automatic moved to a debugger on every mistake a little annoying at this time. Is there a way to turn it off temporarily when I'm playing around.

Ajar answered 19/6, 2010 at 6:25 Comment(0)
N
15

Common Lisp has a variable *debugger-hook*, which can be bound/set to a function.

* (aref "123" 10)

debugger invoked on a SB-INT:INVALID-ARRAY-INDEX-ERROR:
  Index 10 out of bounds for (SIMPLE-ARRAY CHARACTER
                              (3)), should be nonnegative and <3.

Type HELP for debugger help, or (SB-EXT:QUIT) to exit from SBCL.

restarts (invokable by number or by possibly-abbreviated name):
  0: [ABORT] Exit debugger, returning to top level.

(SB-INT:INVALID-ARRAY-INDEX-ERROR "123" 10 3 NIL)
0] 0

* (defun debug-ignore (c h) (declare (ignore h)) (print c) (abort))

DEBUG-IGNORE
* (setf *debugger-hook* #'debug-ignore)

#<FUNCTION DEBUG-IGNORE>
* (aref "123" 10)

#<SB-INT:INVALID-ARRAY-INDEX-ERROR {1002A661D1}>
* 
Nordrheinwestfalen answered 19/6, 2010 at 7:13 Comment(4)
That works great, I'm sure one day I'll need the debugger but to test things out it's just a little annoying right now :) Thanks for the answer.Ajar
This causes SB-INT:SIMPLE-READER-ERROR "unmatched close parenthesis" in some situations. See: "unmatched close parenthesis" when SBCL debugger is turned offWeka
Note that princ instead of print will print the explanation and not only the condition object. In that case, we read "Invalid index 10 for (SIMPLE-ARRAY CHARACTER (3)), should be a non-negative integer below 3." instead of #<SB-INT:INVALID-ARRAY-INDEX-ERROR {1002A661D1}>.Hayley
Of course, you can add the code to your .sbclrc file and get a debugger disabled Lisp environment every time you run SBCL.Waterscape
C
13

There is a --disable-debugger command-line option, e.g.:

$ sbcl --disable-debugger

From the man page:

By default when SBCL encounters an error, it enters the builtin debugger, allowing interactive diagnosis and possible intercession. This option disables the debugger, causing errors to print a back‐trace and exit with status 1 instead -- which is a mode of operation better suited for batch processing. See the User Manual on SB-EXT:DISABLE-DEBUGGER for details.

There are also --noinform and --noprint CL options you may find useful.

Commemorative answered 19/6, 2010 at 6:37 Comment(3)
Good find, I was trying to find a way to prevent it from exiting at the end.Ajar
For anyone learning with clisp the equivalent option is: $ clisp -on-error abortImmortelle
Do note, that (disable-debugger) not only disables the debugger, but every error is then fatal and you drop out of SBCL. The option is best for batch programs that are supposed to die and not invoke the interactive debugger. The definition of debugger-hook serves to report errors and then return to the prompt in the REPL.Waterscape

© 2022 - 2024 — McMap. All rights reserved.