What is the difference between
(function (lambda ...))
and
(lambda ...)
and
'(lambda ...)
?
It seems three are interchangeable in a lot of cases.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
They are pretty interchangeable. The answer is that
functionenables the lambda to be byte compiled, whereas the other two do not (and are equivalent). Note: this does not mean thatfunctionactually 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:
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: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:
So, all three variants of using lambda just build up lists that may be used as functions (one of which may be byte compiled).