Use apply when you don't know what the individual arguments are, or how many there are. You can use funcall (or apply) when you do know that.
For example, suppose your list of args to apply the function to is the value of variable foo. Then you would use (apply 'some-fun foo).
If you know that you're going to apply the function to args 3, toto, and 4, in ...
I generally recommend against doing that (better change the functions to take &optional or &rest arguments that are simply ignored), but if you must, the solution I recommend is:
(funcall f arg1 arg2 arg3)
(funcall f arg1 arg2)
Each symbol has a value cell which you can address with symbol-value and a function cell which you can address with symbol-function.
The func in the defun for next-pair-exists-in is the name of the local variable whose value is bound to the first argument in a function call of next-pair-exists-in. The variable func does not have any binding for its function ...
No. As (elisp) Calling Functions tells us, for funcall (and it lets us know that apply is the same):
Special forms and macros are not allowed, because they make sense only when given the unevaluated argument expressions. funcall cannot provide these because, as we saw above, it never knows them in the first place.
I suggest that you think about what you ...
funcall takes a function as its first argument, so you need
if to return a function symbol. You can do that by
sharp-quoting its return value:
(defun a-plus-abs-b (a b)
(funcall (if (> b 0) #'+ #'-) a b))
(a-plus-abs-b 9 4) ; => 13
Elisp is a Lisp-2, which means each symbol can have a function
value and a variable value. When ...
Emacs is a “Lisp-2”: functions and values have separate namespaces. A function definition (defun foo …) and a function call (foo …) use the function slot of the symbol foo. A variable assignment (setq foo …), a variable binding (let ((foo …)) …), and a variable reference x use the value slot of the symbol foo.
To call a function which is stored in the value ...
`funcall' is not supposed to be called with a macro as the FUNCTION argument. The Elisp manual says:
The argument FUNCTION must be either a Lisp function or a primitive function. Special forms and macros are not allowed, because they make sense only when given the unevaluated argument expressions. ‘funcall’ cannot provide these because, as we saw above, ...
In most Lisp dialects, including Emacs Lisp, symbols have a value as a variable which is independent of their function definition. (funcall output-symbol …) refers to the variable-value of output-symbol, not to the function. You could refer to the function instead by passing the symbol itself to funcall: if you pass a symbol to funcall, it uses that symbol's ...
You're missing a quote: (funcall 'output-symbol ?\_)
If you want to call the symbol-function of the symbol output-symbol then you need to pass that symbol. To do that, quote it, so evaluating returns the symbol.
But you don't need to do that. To call a function whose name you already have, just call it directly: (output-symbol ?\_).
But that's no good, ...
Don't quote callback here:
(funcall 'callback data)
Quoted, you've said to call the function named "callback" (i.e. using the function slot of the callback symbol).
What you want to do is call the function in the value of the callback argument:
(funcall callback data)
I can't say I like the idea... but maybe I only need to get used to it. Anyway, I think you can come very close to your goal :
The function help-function-arglist tries hard to find the signature of any given function/subr ; this can be a starting point for rewriting your easy-going-funcall to handle more cases.
Another starting point is the source code of ...