Hot answers tagged

5

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 ...


4

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: (condition-case nil (funcall f arg1 arg2 arg3) (wrong-number-of-arguments (condition-case nil (funcall f arg1 arg2) (wrong-number-of-arguments ......


3

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 ...


2

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 ...


2

(mapcar (lambda (fn) (funcall fn 1)) '(desktop-save-mode show-paren-mode))


2

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 ...


2

`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, ...


1

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)


1

;; -*- lexical-binding : t -*- (defun double-the-function (fn) (lambda (string) (let ((result (funcall fn string))) (concat result result)))) (funcall (double-the-function 'reverse) "abc")


1

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 ...


Only top voted, non community-wiki answers of a minimum length are eligible