Why not quote lambda?

I was told that I should not quote lambda, let's say

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

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

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

However, I do not understand why the latter works (and is also preferred, and now that the latter works, why the first works).

If the lambda expression is defined as another function, we would call

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

to prevent an instant evaluation of my function. I understand lambda expression as an anonymous version of my function. So why not quote lambda?

Thanks!

+8
emacs elisp
source share
1 answer

Using Ch f lambda <RET> :

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

So this answers the question of why you do not need to specify a lambda expression. As for why you shouldn't do this ... I think it has to do with byte compilation. The expressed lambda expression is just plain data. The byte code compiler has no choice but to include the expression in the literature with a constant list in its output. On the other hand, an incorrect lambda expression can be compiled into byte code, which leads to faster execution.

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

+9
source share

All Articles