在 LISP 中是否可以访问函数的形式?
假设我全局定义一个函数:
(defun x (y) (1+ y)) ;; Edit: my first example was too complicated
是否可以将函数 x “强制”到一个列表中,例如:
(x (y) (1+ y))
提前致谢!
PS - @Danlei 的示例在 Clozure CL 中使用特殊标志工作,但是有人知道如何让 FUNCTION-LAMBDA-EXPRESSION 在 SBCL 中工作吗?
Suppose I define a function globally:
(defun x (y) (1+ y)) ;; Edit: my first example was too complicated
Is it possible to "coerce" the function x into a list like:
(x (y) (1+ y))
Thanks in advance!
PS - @Danlei's example works in Clozure CL with a special flag, however does anyone know how to get FUNCTION-LAMBDA-EXPRESSION to work in SBCL?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以尝试 FUNCTION-LAMBDA-EXPRESSION:
但不能保证它有效(“……在所有情况下,实现都可以自由返回“nil,true,nil”……”)。
例如在 CCL 中:
在 SBCL 中,您可以尝试
(setq sb-ext:*evaluator-mode* :interpret)
(未经测试)。也许还有其他方法可以在 SBCL 中实现此目的(您可能会寻找*save-definitions*
的模拟,甚至尝试不同的OPTIMIZE
设置),但我不这样做了解他们。请注意,将*evaluator-mode*
设置为:interpret
后,在 REPL 中输入的函数将不会被编译,因此您可能会遇到性能更差的情况。You could try FUNCTION-LAMBDA-EXPRESSION:
But it's not guaranteed to work ("… implementations are free to return ``nil, true, nil'' in all cases …").
For example in CCL:
In SBCL, you might try
(setq sb-ext:*evaluator-mode* :interpret)
(untested). Maybe there are other ways to achieve this in SBCL (you might look for an analog of*save-definitions*
or even try differentOPTIMIZE
settings), but I don't know about them. Beware that functions entered in the REPL won't be compiled after setting*evaluator-mode*
to:interpret
, so you will probably experience worse performance.在 Common Lisp 中,您也许能够使用
function-lambda-expression
恢复函数的定义(请参阅HyperSpec)或在某些实现中uncompile-function
。In Common Lisp, you might be able to recover the definition of a function using
function-lambda-expression
(see the HyperSpec) or in some implementationsuncompile-function
.当我花时间在一个项目上进行重要的函数操作时,最容易做这种事情:
首先分配由 '(lambda foo (x ) bar) 组成的列表形式,然后我会编译 Foo 并分配将其添加到已编译的 ojb 插槽中。
When I was spending time on a project to do significant function manipulation, it was easiest to do this sort of thing:
First the list form consisting of '(lambda foo (x ) bar) would be assigned, then I would compile Foo and assign it to the compiled-ojb slot.