Document apply-partially as inefficient

* doc/lispref/functions.texi (Calling Functions): Document that it is
less inefficient than a regular 'lambda'.
* lisp/subr.el (apply-partially): Adjust documentation like above and
remove compiler macro.
Ref: https://lists.gnu.org/r/emacs-devel/2025-03/msg00024.html
This commit is contained in:
Stefan Kangas 2025-03-02 05:46:56 +01:00
parent eff5a3e43b
commit 33222bd000
2 changed files with 18 additions and 7 deletions

View file

@ -1055,7 +1055,17 @@ The result is a new function that accepts the rest of
arguments and calls the original function with all the arguments
combined.
Here's how to do partial application in Emacs Lisp:
In Emacs Lisp, this is best done with an anonymous function. For
example, if you have a function @samp{my-function} that takes two
arguments, you could do something like this:
@example
(mapcar (lambda (x) (my-function 123 x)) @dots{})
@end example
You can also do partial application using the function
@code{apply-partially}. However, this will be slower than using an
anonymous function with @code{lambda}.
@defun apply-partially func &rest args
This function returns a new function which, when called, will call

View file

@ -536,12 +536,13 @@ configuration."
ARGS is a list of the first N arguments to pass to FUN.
The result is a new function which does the same as FUN, except that
the first N arguments are fixed at the values with which this function
was called."
(declare (side-effect-free error-free)
(compiler-macro
(lambda (_)
`(lambda (&rest args2)
,`(apply ,fun ,@args args2)))))
was called.
In almost all cases, you want to use a regular anonymous function
defined with `lambda' instead. It will be faster, because it does not
have the overhead of calling `apply' and `append', which this function
has to do internally."
(declare (side-effect-free error-free))
(lambda (&rest args2)
(apply fun (append args args2))))