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

标签 common-lisp sbcl 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

最佳答案

长话短说,关于 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/

相关文章:

common-lisp - `eval-when` 的意外行为

emacs - 在 "Slime"(最新版本)中设置 "emacs"时,我如何告诉它更快地加载 swank?

list - 如何将 char 转换为 common lisp 中的符号?

common-lisp - 用于控制转移的 Common Lisp 条件系统

common-lisp - common-lisp中有关可选参数的错误

parallel-processing - Common Lisp (SBCL) 是否具有高级并行功能?

common-lisp - CFFI-UNIX 发生了什么?

emacs - 在程序运行时更改程序

lisp - 使用嵌套列表 LISP

lisp - 如何存储lispbuilder-sdl :colors in a list?