The 'funcall' function calls a function with a series of arguments. It returns the result from calling the function with the arguments.
(funcall '+ 1 2 3 4) ; returns 10 (funcall #'+ 1 2 3 4) ; returns 10 (funcall '+ '1 '2 '3) ; returns 6 (setq sys-add (function +)) ; returns #<Subr-+: #22c32> (setq a 99) (funcall sys-add 1 a) ; 100 (funcall sys-add 1 'a) ; error: bad argument type ; you can't add a symbol, only it's value (setq a 2) ; set A (setq b 3) ; and B values (funcall (if (< a b) (function +) ; 'function' can be computed (function -)) a b) ; returns 5 (defun add-to-list (arg list) ; add a list or an atom (funcall (if (atom arg) 'cons ; to the front of a list 'append) arg list)) (add-to-list 'a '(b c)) ; returns (A B C) (add-to-list '(a b) '(b c)) ; returns (A B B C)
See the
funcall
function in the