2

I'm confused about return value of apply-partially. Documentation states that it returns a function, and source of the function shows that it actually retruns a lambda. But I can't invoke the return value directly, only via funcall. Creating lambda directly at the call place allows me to invoke it directly.

Here are three examples of what am I talking about:

((apply-partially 'string-prefix-p ".") ".emacs")
;; => (invalid-function (apply-partially 'string-prefix-p "."))
((lambda (x) (string-prefix-p "." x)) ".emacs")
;; => t
(funcall (apply-partially 'string-prefix-p ".") ".emacs")
;; => t

Why is it working in such way?

2

((lambda ...) ...) is a special case, and IIRC the only such special case.

Lots of elisp functions return functions, and apply-partially is no different to any of the others in this regard.

source of the function shows that it actually returns a lambda

Most functions are (ultimately) lambdas. See C-hig (elisp)What Is a Function for details.

C-hig (elisp)Function Indirection might also be of interest.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.