I'm playing around with apply-partially
and I'm confused about what gets returned when calling this function. The documentation states that apply-partially
returns a function, but then I'd expect to be able to do the following:
(defun add-numbers (a b)
(+ a b))
(defun add2 (apply-partially 'add-numbers 2))
and then call the function:
(add2 3)
OR:
(funcall add2 3)
Unfortunately this throws an error. When I do everything inside of a let
, however, it does work and I get "5" back:
(let ((add2 (apply-partially 'add-numbers 2)))
(funcall add2 3))
I thought maybe the difference was that let doesn't use defun
, as I do above, but then I would expect the following to work:
(defvar add2 (apply-partially 'add-numbers 2))
(funcall
add2 3)
but that doesn't work either. So what am I missing? Is it not possible to assign the return value of apply-partially
outside of a let
?