这是我在Hyperspec处看到的示例:

(setq fstr (make-array '(0) :element-type 'base-char
                             :fill-pointer 0 :adjustable t))
(with-output-to-string (s fstr)
    (format s "here's some output"))


因此,fstr保持here's some output问:如果要重新开始并在其中添加新内容,即不进行更多连接,如何对fstr进行简单的清除/重置?还是只需要重做设置fstr的顶部表达式?

最佳答案

设置填充指针:

CL-USER 3 > (setq fstr (make-array '(0) :element-type 'base-char
                                   :fill-pointer 0 :adjustable t))
""

CL-USER 4 > (with-output-to-string (s fstr)
              (format s "here's some output"))
NIL

CL-USER 5 > fstr
"here's some output"

CL-USER 6 > (setf (fill-pointer fstr) 0)
0

CL-USER 7 > fstr
""

CL-USER 8 > (with-output-to-string (s fstr)
              (format s "here's some more output"))
NIL

CL-USER 9 > fstr
"here's some more output"


您也可以调用adjust-array实际更改数组大小。

CL-USER 16 > (setf (fill-pointer fstr) 0)
0

CL-USER 17 > (adjust-array fstr 0)
""

09-11 19:21