"unmatched close parenthesis" 当 SBCL 调试器关闭时

"unmatched close parenthesis" when SBCL debugger is turned off

how to turn off the debugger in sbcl中,其中一个答案说可以通过设置*debugger-hook*:

来关闭调试器
(defun debug-ignore (c h)
  (declare (ignore h))
  (print c)
  (abort))

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

但是,这似乎在某些情况下会导致 "unmatched close parenthesis" 错误。例如,这是当我输入 (foo:bar 123) 时 SBCL REPL 中发生的情况,其中 foobar 不存在:

* (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}> 
* 

据我了解,出现这个"unmatched close parenthesis"错误是因为在"Package ~A does not exist."错误之后,还有 123)待读。读到 123)时,因为括号不匹配而出错。这似乎是 SBCL 特有的,因为当我在 CLISP 中执行上述操作时不会发生 "unmatched close parenthesis" 错误。

由于 how to turn off the debugger in sbcl 中的答案不完全正确,我如何在不遇到这些 "unmatched close parenthesis" 错误的情况下实际禁用 SBCL 中的调试器?

对于这个特定问题,您可以调用 clear-input 以便丢弃任何剩余的要读取的输入:

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