aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/lispref/functions.texi16
1 files changed, 9 insertions, 7 deletions
diff --git a/doc/lispref/functions.texi b/doc/lispref/functions.texi
index 4609fc18cef..e420e932fc7 100644
--- a/doc/lispref/functions.texi
+++ b/doc/lispref/functions.texi
@@ -727,7 +727,7 @@ of mapcar}.
727 727
728@cindex partial application of functions 728@cindex partial application of functions
729@cindex currying 729@cindex currying
730 Sometimes, it is useful to fix some of the function's arguments at 730 Sometimes it is useful to fix some of the function's arguments at
731certain values, and leave the rest of arguments for when the function 731certain values, and leave the rest of arguments for when the function
732is actually called. The act of fixing some of the function's 732is actually called. The act of fixing some of the function's
733arguments is called @dfn{partial application} of the function@footnote{ 733arguments is called @dfn{partial application} of the function@footnote{
@@ -737,7 +737,9 @@ it can be called as a chain of functions, each one with a single
737argument.}. 737argument.}.
738The result is a new function that accepts the rest of 738The result is a new function that accepts the rest of
739arguments and calls the original function with all the arguments 739arguments and calls the original function with all the arguments
740combined. Emacs provides a function for partial evaluation: 740combined.
741
742 Here's how to do partial application in Emacs Lisp:
741 743
742@defun apply-partially func &rest args 744@defun apply-partially func &rest args
743This function returns a new function which, when called, will call 745This function returns a new function which, when called, will call
@@ -747,14 +749,14 @@ accepts @var{n} arguments, then a call to @code{apply-partially} with
747@w{@code{@var{m} < @var{n}}} arguments will produce a new function of 749@w{@code{@var{m} < @var{n}}} arguments will produce a new function of
748@w{@code{@var{n} - @var{m}}} arguments. 750@w{@code{@var{n} - @var{m}}} arguments.
749 751
750Here's an example of using @code{apply-partially} to produce a 752Here's an example of using @code{apply-partially} to produce a variant
751function @code{incr}, that will increment its argument by one, based 753of the Emacs Lisp primitive @code{1+}, a function that increments its
752on the Emacs Lisp primitive @code{+}: 754argument by one, based on the primitive @code{+}:
753 755
754@example 756@example
755(fset 'incr (apply-partially '+ 1)) 757(fset 'incr-by-one (apply-partially '+ 1))
756@group 758@group
757(incr 10) 759(incr-by-one 10)
758 @result{} 11 760 @result{} 11
759@end group 761@end group
760@end example 762@end example