1

I made a list of functions. (caar flist) is a function according to functionp. But Emacs says invalid function. How can i use it?

(setq flist '((< +) (> -)))
--> ((< +) (> -))
(caar flist)
--> <
(functionp (caar flist))
--> t

((caar flist) 1 3)
--> invalid function (caar flist)
8
  • 2
    C-h i g (elisp)Calling Functions Commented Aug 11 at 8:14
  • 1
    funcall? It's a new function for me. Thank you for the quick response. Commented Aug 11 at 10:49
  • 2
    Yes indeed, and you're welcome. Elisp is a "lisp-2" where the "2" means that function names and variable names are in two distinct name-spaces, and hence there can be both a function and a variable with any given name foo. Because of that, there needs to be more than just the syntax (foo ...) as we need to distinguish between calling the function of that name, or evaluating the variable foo to a function value and calling that. So (foo ...) only ever calls the function by that name, while funcall and apply can be used to call functions stored as other values. Commented Aug 11 at 12:03
  • 1
    So your error invalid function (caar flist) is not saying that (caar flist) doesn't evaluate to a function, but rather that the form (caar flist) itself is not a function (as it's actually a list of two symbols). Commented Aug 11 at 12:05
  • 1
    Your beautiful explanation is easier to understand than the Emacs manual. I've finally begun to understand that Elisp is an interesting language. List is fantastic! Thank you so much. Commented Aug 11 at 15:25

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.