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
?
(defun add2 (....))
can't work becausedefun
sees(apply-partially 'add-numbers 2)
as an argument list.apply-partially
never actually gets called here. So that means the(defun add (...))
call CAN'T work, leaving only the(defvar add2 (...))
towards the bottom.defalias
defalias
allows me to call the return value ofapply-partially
in the following way:(add2 3)
, i.e. as a normal function.(funcall add2 3)
doesn't work, but that's also not a problem. Thanks :)