限制调试输出中的字符串长度

And*_*rei 4 sbcl common-lisp slime

我使用 emacs、slime 和 sbcl。当条件发生时我被扔进调试器时,如何限制输出的大小?我已经弄清楚了*print-length**print-level*,但是对于长字符串或多行字符串该怎么办?说,

(defun monkeys (length)
  "Generate a random string"
  (with-output-to-string (out)
    (dotimes (i length)
      (write-char
       (code-char
        (let ((c (random 27)))
          (if (zerop c)
              (if (zerop (random 5)) 10 32)
              (+ 95 c)))) out))))

(1+ (monkeys 10000)) ; drop into debugger
Run Code Online (Sandbox Code Playgroud)

And*_*rei 5

长话短说,在sbcl上*print-vector-length*就可以用了。来自SBCL源代码:

(defparameter *print-vector-length* nil
  "Like *PRINT-LENGTH* but works on strings and bit-vectors.
Does not affect the cases that are already controlled by *PRINT-LENGTH*")
Run Code Online (Sandbox Code Playgroud)

长话短说,我从没想过要查看源代码。不过,多亏了@tfb 的回答,我至少有了一个起点。因此,我继续阅读有关漂亮打印机的调度表的信息,并且,为了了解调度函数的外观,我检查了默认调度函数的内容'string

(pprint-dispatch 'string)
Run Code Online (Sandbox Code Playgroud)

这给出了#<FUNCTION SB-KERNEL:OUTPUT-UGLY-OBJECT>. 我在SBCL源代码中搜索了一下,一路找到了必要的参数。