为什么不引用lambda? [英] Why not quoting lambda?

查看:124
本文介绍了为什么不引用lambda?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被告知,我不应该引用lambda,例如

I was told that I shouldn't quote lambda in, say,

(global-set-key (quote [f3]) '(lambda ()   (interactive) (other-window -1) ))

尝试,如果我不引用lambda,它的工作同样好

I tried that indeed if I don't quote lambda, it works equally well

(global-set-key (quote [f3]) (lambda ()   (interactive) (other-window -1) ))

不明白为什么后者可以工作(而且也是首选,现在后者的作用,为什么前者也有效)。

However, I don't understand why the latter works (and is also being preferred, and now that the latter works, why the former also works).

如果lambda表达式被定义为另一个函数,我们将调用

If the lambda expression is defined as an other function, we would have called

(global-set-key (quote [f3]) 'my-function)

以防止我的功能被马上评估。我将lambda表达式理解为my-function的匿名版本。那么为什么不要引用lambda?

to prevent my-function to be evaluated immediately. I understand the lambda expression as an anonymous version of my-function. So why shouldn't lambda be quoted?

谢谢!

推荐答案

使用 Ch f lambda< RET>


表单的调用(lambda ARGS DOCSTRING INTERACTIVE BODY)
是自我引用的;评估lambda表达式
的结果是表达式本身。

A call of the form (lambda ARGS DOCSTRING INTERACTIVE BODY) is self-quoting; the result of evaluating the lambda expression is the expression itself.

所以,这回答了这个问题,为什么你不t需要引用lambda表达式。至于为什么你不应该这样做...我认为这与字节编译有关。引用的lambda表达式只是简单的数据。字节代码编译器别无选择,只能将表达式作为常量列表文字包含在其输出中。另一方面,一个无引号的lambda表达式可以被编译成字节码,导致更快的执行。

So, this answers the question, why you don't need to quote the lambda expression. As to why you shouldn't do it... I think, this has to do with byte compilation. A quoted lambda expression is simply plain data. The byte code compiler has no choice but to include the expression as a constant list literal into its output. An unquoted lambda expression, on the other hand, can be compiled to byte code, resulting in faster execution.

列出文本(lambda (...)...)是特殊的emacs lisp评估器,可以用作函数。这就是为什么它的工作原理,无论你是否引用lambda表达式。

List literals of the form (lambda (...) ...) are special-cased in emacs lisp evaluator and can be used as functions. That's why it works, regardless of whether you quote the lambda expression or not.

这篇关于为什么不引用lambda?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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