13

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.

Rainer Joswig
  • 136,269
  • 10
  • 221
  • 346
nkassis
  • 5,285
  • 2
  • 21
  • 22

2 Answers2

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}>
* 
Rainer Joswig
  • 136,269
  • 10
  • 221
  • 346
  • 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. – nkassis Jun 19 '10 at 18:04
  • This causes `SB-INT:SIMPLE-READER-ERROR "unmatched close parenthesis"` in some situations. See: ["unmatched close parenthesis" when SBCL debugger is turned off](https://stackoverflow.com/questions/69280179/unmatched-close-parenthesis-when-sbcl-debugger-is-turned-off) – Flux Sep 22 '21 at 07:51
  • 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 `#`. – Ehvince Oct 18 '21 at 14:55
  • Of course, you can add the code to your .sbclrc file and get a debugger disabled Lisp environment every time you run SBCL. – kd4ttc Aug 23 '23 at 17:11
11

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.

mechanical_meat
  • 163,903
  • 24
  • 228
  • 223