Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

funcall vs apply with lambda in elisp

In elisp why does funcalling a lambda work, but applying it raises an error?

ELISP> (funcall (lambda ()))
nil
ELISP> (apply (lambda ()))
*** Eval error ***  Invalid function: lambda
like image 236
rhlee Avatar asked Sep 12 '26 11:09

rhlee


2 Answers

My emacs gives another error:

*** Eval error ***  Wrong number of arguments: apply, 1

I think it explains everything.

like image 116
monoid Avatar answered Sep 15 '26 02:09

monoid


Apply must be given arguments, see the (describe-function) result:

apply is a built-in function in `C source code'.

(apply FUNCTION &rest ARGUMENTS)

Call FUNCTION with our remaining args, using our last arg as list of args.
Then return the value FUNCTION returns.
Thus, (apply '+ 1 2 '(3 4)) returns 10.

[back]
like image 24
Jordon Biondo Avatar answered Sep 15 '26 02:09

Jordon Biondo