首页 > 解决方案 > 限制调试输出中的字符串长度

问题描述

我使用 emacs、slime 和 sbcl。当条件发生时我被扔进调试器时,如何限制输出的大小?我已经弄清楚*print-length*and *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

标签: common-lispsbclslime

解决方案


长话短说,在 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*")

长话短说,我不知何故从未想过要看源代码。但是,感谢@tfb 的回答,我至少有了一个起点。所以我继续阅读漂亮打印机的调度表,为了看看调度函数的外观,我检查了默认调度函数'string是什么:

(pprint-dispatch 'string)

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


推荐阅读