如何从SBCL解释器写入特定的函数文件?

aka*_*nuk 3 serialization common-lisp

说我玩SBCL有点没有SLIME,没有任何简单的翻译.现在我想在文件中保存几个函数.不是核心图像,只是文本形式的一些代码.我该怎么办?

Rai*_*wig 7

有两种方法可以做到:使用DRIBBLE和/或FUNCTION-LAMBDA-EXPRESSION

第一种是DRIBBLE在试验之前始终使用Common Lisp函数:

rjmba:tmp joswig$ sbcl
This is SBCL 1.1.9, 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.
Run Code Online (Sandbox Code Playgroud)

Dribble采用文本文件的路径名.调用后,交互式IO将写入该文件.

* (dribble "/Lisp/tmp/2013-09-06-01.text")

* (defun foo (a) (1+ a))

FOO
* (foo 10)

11
* (quit)
Run Code Online (Sandbox Code Playgroud)

看文件:

rjmba:tmp joswig$ cat 2013-09-06-01.text 

* (defun foo (a) (1+ a))

FOO
* (foo 10)

11
* (quit)
Run Code Online (Sandbox Code Playgroud)

从上面你应该能够看到你是否输入了任何有趣的功能......你也可以设置你的SBCL(例如使用init文件)来始终设置运球.(dribble)没有参数的呼叫结束了运球.

下一个FUNCTION-LAMBDA-EXPRESSION ::

* (defun foo (b) (1- b))

FOO
Run Code Online (Sandbox Code Playgroud)

现在您可以调用FUNCTION-LAMBDA-EXPRESSION以获取定义.它可能会略有改变,但它应该能够恢复以代码编写的有价值的想法:

* (function-lambda-expression #'foo)

(SB-INT:NAMED-LAMBDA FOO
    (B)
  (BLOCK FOO (1- B)))
NIL
FOO
Run Code Online (Sandbox Code Playgroud)

  • 我意识到我也有一份1.1.1副本.在那里,我得到了你发布的相同结果.我想要提出的是来自[function-lambda-expression](http://clhs.lisp.se/Body/f_fn_lam.htm)"[任何]实现可以合法地返回nil作为任何函数的lambda表达式,"过去版本的SBCL似乎已经做到了这一点.(这出现在[过去的问题](http://stackoverflow.com/q/5844670/1281433).) (2认同)