它们非常可以互换。答案是function
enableslambda 要进行字节编译,而其他两个则不需要(并且是等效的)。Note:这并不意味着function
实际上对 lambda 进行了字节编译。
How might one figure that out? A little Emacs lisp introspection provides some clues. To start: C-h f function RET:
函数是 'C 中的特殊形式
源代码'。
(函数参数)
类似于“quote”,但首选
对象是函数。以字节为单位
编译,“功能”导致其
要编译的参数。 '引用'
不可以这样做。
Ok, so that's the difference between (function (lambda ...))
and '(lambda ...)
, the first tells the byte compiler that it may safely compile the expression. Whereas the 'ed expressions may not necessarily be compiled (for they might just be a list of numbers.
What about just the bare (lambda ...)
? C-h f lambda RET shows:
lambda 是 `subr.el' 中的一个 Lisp 宏。
(lambda args [文档字符串] [交互]
身体)
返回 lambda 表达式。一个电话
形式(lambda args 文档字符串
交互体)是自引用的;这
计算 lambda 的结果
表达式就是表达式本身。
那么 lambda 表达式可以是
被视为函数,即存储为
符号的函数值,传递
'funcall' 或 'mapcar' 等。
所以,(lambda ...)
and '(lambda ...)
是等价的。
另外,还有一个记号#'(lambda ...)
,这是语法糖(function (lambda ...))
.
有关 Emacs lisp 中函数的更多信息,请阅读功能信息页面.
为了检查所有这些,您可以在 *scratch* 缓冲区中输入以下内容并计算表达式:
(caddr '(lambda (x) (+ x x)))
(+ x x)
(caddr (lambda (x) (+ x x)))
(+ x x)
(caddr (function (lambda (x) (+ x x))))
(+ x x)
(equal '(lambda (x) (+ x x))
(function (lambda (x) (+ x x))))
t
(equal '(lambda (x) (+ x x))
(lambda (x) (+ x x)))
t
因此,使用 lambda 的所有三种变体都只是构建可用作函数的列表(其中之一可以是字节编译的)。