抑制Lisp中print函数的输出

Nyl*_*les 4 lisp common-lisp

我是Lisp的新手,我遇到了打印问题.我有一个函数可以打印到标准输出(除其他外).我想通过另一个函数运行此函数,它仍然运行相同但没有任何东西被打印到标准输出.

这是我的意思的一个简单例子.我有以下两个功能描述:

(defun does-printing()
  (print "This goes to standard output."))

(defun run-other-function (function)
  (funcall function)
  (values))
Run Code Online (Sandbox Code Playgroud)

这是我运行时发生的运球,

;; Dribble of #<IO TERMINAL-STREAM> started on 2014-10-05 21:49:49.
#<OUTPUT BUFFERED FILE-STREAM CHARACTER #P"example.out">
[7]> (run-other-function #'does-printing)

"This goes to standard output." 

[8]> (dribble)
;; Dribble of #<IO TERMINAL-STREAM> finished on 2014-10-05 21:50:09.
Run Code Online (Sandbox Code Playgroud)

请注意,打印功能仍然打印到标准输出.它希望能够通过run-other-function运行打印时以某种方式抑制此打印.在搜索解决方案时,我已经尝试了许多不同的措辞,但我没有想到要做什么.

Rai*_*wig 10

最简单的解决方案是创建一个空的广播流.

(with-open-stream (*standard-output* (make-broadcast-stream))
  (call-some-function-1)
  ...
  (call-some-function-n))
Run Code Online (Sandbox Code Playgroud)

如果广播流没有组件流,则将丢弃所有输出.上面绑定*standard-output*到这样的流.这不会消耗任何数据,而且是便携式的.