我使用 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
最佳答案
长话短说,关于 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 的回答,我至少有了一个起点。所以我继续阅读 pretty-print 的调度表,为了看看调度函数的外观,我检查了 'string
的默认调度函数是什么。是:
(pprint-dispatch 'string)
这给出了 #<FUNCTION SB-KERNEL:OUTPUT-UGLY-OBJECT>
.我在SBCL源码中搜索了一下,一路上找到了必要的参数。
关于common-lisp - 限制调试输出中的字符串长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61456900/