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?

Drew
  • 75,699
  • 9
  • 109
  • 225
Rogach
  • 267
  • 1
  • 5

1 Answers1

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.

phils
  • 48,657
  • 3
  • 76
  • 115
  • I've rejected the following as an edit to the answer because it's not what the question was about; but in case anyone else arrives at this Q&A with this same requirement, another user wished to point out that you can define a function like so `(defalias 'dot-prefix-p (apply-partially 'string-prefix-p "."))` which can be called like this `(dot-prefix-p ".emacs")`. – phils Sep 17 '21 at 04:11