Emacs Lisp:(function(lambda ...))和(lambda ...)之间的差异? [英] Emacs Lisp: difference between (function (lambda ...)) and (lambda ...)?

查看:255
本文介绍了Emacs Lisp:(function(lambda ...))和(lambda ...)之间的差异?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

之间的区别

 (function(lambda ...))

 

 code>'(lambda ...)



在很多情况下,似乎三个是可以互换的。

解决方案

答案是 function 启用 lambda被字节编译,而其他两个不(和等效)。 注意:这并不意味着 function 实际上是字节编译lambda。



可能有人想出来?一个小Emacs lisp内省提供了一些线索。开始: Ch f function RET


函数是'C
source中的一种特殊形式代码'。



(函数arg)



像'quote',但优先于
这是功能。在byte
编译中,'function'导致
参数被编译。


好的,这是 lambda ...))'(lambda ...),首先告诉字节编译器它可以安全地编译表达式。而'编辑表达式可能不一定要编译(因为他们可能只是一个数字列表。



c $ c>(lambda ...)? Ch f lambda RET 显示:


lambda是`subr.el'中的Lisp宏。



(lambda args [docstring] [interactive]
body)



返回一个lambda表达式
的调用形式(lambda args docstring
交互式主体)是自引号;
计算lambda的结果
表达式是表达式本身
lambda表达式可以是
当作一个函数,即存储为一个符号的函数值
,传递
到'funcall'或'mapcar'等。


因此,(lambda ...)'(lambda ...)是等效的。



code>#'(lambda ...),它是(function(lambda ...))的语法糖。 / p>

有关Emacs lisp中函数的更多信息,请阅读函数信息页



只需检查所有这些,您可以在*缓冲区并计算表达式:

 (caddr'(lambda(x)(+ xx)))
xx)

(caddr(lambda(x)(+ xx)))
(+ xx)

xx)))
(+ xx)

(等于'(lambda(x)(+ xx))
))
t

(等于'(lambda(x)(+ xx))
(lambda(x)(+ xx)))
t

所以,使用lambda的所有三个变体只是构建可以用作函数的列表编译)。


What is the difference between

(function (lambda ...))

and

(lambda ...) 

and

'(lambda ...)

?

It seems three are interchangeable in a lot of cases.

解决方案

They are pretty interchangeable. The answer is that function enables the lambda to be byte compiled, whereas the other two do not (and are equivalent). Note: this does not mean that function actually byte compile the lambda.

How might one figure that out? A little Emacs lisp introspection provides some clues. To start: C-h f function RET:

function is a special form in 'C source code'.

(function arg)

Like 'quote', but preferred for objects which are functions. In byte compilation, 'function' causes its argument to be compiled. 'quote' cannot do that.

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 is a Lisp macro in `subr.el'.

(lambda args [docstring] [interactive] body)

Return a lambda expression. A call of the form (lambda args docstring interactive body) is self-quoting; the result of evaluating the lambda expression is the expression itself. The lambda expression may then be treated as a function, i.e., stored as the function value of a symbol, passed to 'funcall' or 'mapcar', etc.

Therefore, (lambda ...) and '(lambda ...) are equivalent.

Also, there is the notation #'(lambda ...), which is syntactic sugar for (function (lambda ...)).

For more information on functions in Emacs lisp, read the Functions info pages.

Just to check all this, you can type the following into the *scratch* buffer and evaluate the expressions:

(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

So, all three variants of using lambda just build up lists that may be used as functions (one of which may be byte compiled).

这篇关于Emacs Lisp:(function(lambda ...))和(lambda ...)之间的差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆