为什么运球会产生一个空文件?

问题描述

我正在尝试通过Common Lisp:符号计算的温和介绍这本书来学习 Common Lisp。此外,我正在使用 SBCL、Emacs 和 Slime。

在第 9 章结束时,作者展示了 dribble 工具。 他显示了以下内容

enter image description here

enter image description here

我试图重现作者提供的命令。考虑到输入,唯一的区别是我放置了不同的位置来保存文件。在我的环境中,我做到了:

CL-USER> (dribble "/home/pedro/miscellaneous/misc/symbolic-computation/teste-tool.log")
; No value
CL-USER> (cons 2 nil)
(2)
CL-USER> '(is driblle really working?)
(IS DRIBLLE REALLY WORKING?)
CL-USER> "is dribble useful at all?"
"is dribble useful at all?"
CL-USER> (dribble)
; No value

文件确实已创建:

$ readlink -f teste-tool.log 
/home/pedro/miscellaneous/misc/symbolic-computation/teste-tool.log

请注意,我在打字时没有在 REPL 中收到诸如“现在正在文件 --location --- 中记录”之类的消息。但这可能会因 Lisp 实现而异。

令人惊讶的是,不幸的是,文件是空的。因此,运球没有按预期工作。

我做错了吗?

解决方法

  1. 是的,默认情况下,在 Slime 中,我认为这行不通。

  2. 在 SBCL Repl 中工作:

➜ sbcl
This is SBCL 2.0.1.debian,an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.

SBCL is free software,provided as is,with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses.  See the CREDITS and COPYING files in the
distribution for more information.
* (dribble "dribble-test.lisp")
* (* 8 5)

40
* "Will this work?"

"Will this work?"
* (dribble)

* %

哪些可以确认:

➜ cat dribble-test.lisp
* (* 8 5)

40
* "Will this work?"

"Will this work?"
* (dribble)
  1. 保存“REPL 历史记录”对于 Slime IMO 似乎不太有用,因为您执行的所有“非 REPL 评估”例如选择函数、表达式或区域并在 REPL 中对其求值。

  2. 实际上在 Slime 中保存和查看历史记录,请参阅 slime-repl-save-history 和相关函数;如果您愿意,您甚至可以合并来自独立 Repls 的历史 :-)