common-lisp - 限制调试输出中的字符串长度
问题描述
我使用 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
解决方案
长话短说,在 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源代码中搜索,一路上找到了必要的参数。
推荐阅读
- reactjs - 每次用户登录时,firebase 数据库中的新节点
- html - 前景中的白线
- mysql - SQL中按年份排序
- java - 按钮不显示日志或吐司
- apache-flink - Flink:仅在会话窗口结束时计算
- html - 使用 rem 声明的标题边距的参考属性是什么?
- mongodb - MongoDB:在嵌套数组中更新
- android - 使用 Flutter 执行任务 ':app:processReleaseResources' image_picker 失败
- java - 包 org.junit 不存在 Java Netbeans
- bash - 这个 bash 脚本中的两颗星在做什么?只是否定?