Search code examples
common-lispsbcl

"unmatched close parenthesis" when SBCL debugger is turned off


In how to turn off the debugger in sbcl, one of the answers says that the debugger can be turned off by setting *debugger-hook*:

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

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

However, this seems to cause an "unmatched close parenthesis" error in some circumstances. For example, this is what happens in the SBCL REPL when I enter (foo:bar 123), where foo and bar are non-existent:

* (foo:bar 123)
#<FUNCTION DEBUG-IGNORE>
* 
#<SB-INT:SIMPLE-READER-PACKAGE-ERROR "Package ~A does not exist." {100187B653}> 
* 123
* 
#<SB-INT:SIMPLE-READER-ERROR "unmatched close parenthesis" {100187CE23}> 
* 

From my understanding, this "unmatched close parenthesis" error occurs because after the "Package ~A does not exist." error, there is 123) still remaining to be read. When 123) is read, there is an error because the parenthesis is unmatched. This seems to be specific to SBCL, since the "unmatched close parenthesis" error does not occur when I do the above in CLISP.

Since that answer in how to turn off the debugger in sbcl is not entirely correct, how do I actually disable the debugger in SBCL without encountering these "unmatched close parenthesis" errors?


Solution

  • For this specific problem you can call clear-input so that any remaining input to be read is discarded:

    (defun debug-ignore (c h)
      (declare (ignore h))
      (print c)
      (clear-input)
      (abort))