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

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

问题描述

 (function(lambda ...))

 (lambda ... )

 code>'(lambda ...)



在许多情况下,似乎有三个可以互换。

解决方案

它们是可互换的。答案是,函数 使lambda能够被字节编译,而其他两个不(并且是等效的)。注意:这并不意味着函数实际是字节编译lambda。



可能有一个人出来吗?一点点Emacs lisp内省提供了一些线索。开始:函数RET


函数是'C
源中的一个特殊表单代码'。



(function arg)



像'quote'一样,但是对于
对象哪些是功能。在字节
编译中,'function'使得
参数被编译。 ''
不能这样做。


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



只是裸体code>(lambda ...)? Ch f lambda RET 显示:


lambda是subr.el中的Lisp宏。



(lambda args [docstring] [interactive]
body)



返回一个lambda表达式。
的表单(lambda args docstring
interactive body)的调用是自引用的;评估lambda的
结果
表达式是表达式本身
lambda表达式可能会被当作一个函数处理,即存储为
符号的函数值,将
传递给'funcall'或'mapcar'等。


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



另外, code>#'(lambda ...),这是句法(function(lambda ...))



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



只需检查所有这些,您可以在* scratch *缓冲区中键入以下内容并评估表达式:

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

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

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

(equal' lambda(x)(+ xx))
(function(lambda(x)(+ xx))))
t

(等于((x) ))
(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天全站免登陆