aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2008-10-19 14:57:50 +0000
committerEli Zaretskii2008-10-19 14:57:50 +0000
commit80f85d7cda750c0ee0c4e0a2f9646b27c37fb52f (patch)
treeaaa38c59e9e6a6a639d3ba68851adae31a718ed9
parentd24ae8f0576120bc5c4cef7e7651d1d53684466b (diff)
downloademacs-80f85d7cda750c0ee0c4e0a2f9646b27c37fb52f.tar.gz
emacs-80f85d7cda750c0ee0c4e0a2f9646b27c37fb52f.zip
(Calling Functions): Document `apply-partially'.
-rw-r--r--doc/lispref/ChangeLog2
-rw-r--r--doc/lispref/functions.texi35
-rw-r--r--etc/NEWS1
3 files changed, 38 insertions, 0 deletions
diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog
index 55343fcbdf7..ffb7b48cb4c 100644
--- a/doc/lispref/ChangeLog
+++ b/doc/lispref/ChangeLog
@@ -1,5 +1,7 @@
12008-10-19 Eli Zaretskii <eliz@gnu.org> 12008-10-19 Eli Zaretskii <eliz@gnu.org>
2 2
3 * functions.texi (Calling Functions): Document `apply-partially'.
4
3 * hooks.texi (Standard Hooks): Mention 5 * hooks.texi (Standard Hooks): Mention
4 `before-hack-local-variables-hook' and `hack-local-variables-hook'. 6 `before-hack-local-variables-hook' and `hack-local-variables-hook'.
5 7
diff --git a/doc/lispref/functions.texi b/doc/lispref/functions.texi
index 068d05ffc99..4609fc18cef 100644
--- a/doc/lispref/functions.texi
+++ b/doc/lispref/functions.texi
@@ -725,6 +725,41 @@ For an interesting example of using @code{apply}, see @ref{Definition
725of mapcar}. 725of mapcar}.
726@end defun 726@end defun
727 727
728@cindex partial application of functions
729@cindex currying
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
732is actually called. The act of fixing some of the function's
733arguments is called @dfn{partial application} of the function@footnote{
734This is related to, but different from @dfn{currying}, which
735transforms a function that takes multiple arguments in such a way that
736it can be called as a chain of functions, each one with a single
737argument.}.
738The result is a new function that accepts the rest of
739arguments and calls the original function with all the arguments
740combined. Emacs provides a function for partial evaluation:
741
742@defun apply-partially func &rest args
743This function returns a new function which, when called, will call
744@var{func} with the list of arguments composed from @var{args} and
745additional arguments specified at the time of the call. If @var{func}
746accepts @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
748@w{@code{@var{n} - @var{m}}} arguments.
749
750Here's an example of using @code{apply-partially} to produce a
751function @code{incr}, that will increment its argument by one, based
752on the Emacs Lisp primitive @code{+}:
753
754@example
755(fset 'incr (apply-partially '+ 1))
756@group
757(incr 10)
758 @result{} 11
759@end group
760@end example
761@end defun
762
728@cindex functionals 763@cindex functionals
729 It is common for Lisp functions to accept functions as arguments or 764 It is common for Lisp functions to accept functions as arguments or
730find them in data structures (especially in hook variables and property 765find them in data structures (especially in hook variables and property
diff --git a/etc/NEWS b/etc/NEWS
index a91f17e101c..6a7783e6293 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1581,6 +1581,7 @@ times the default column width.
1581*** `format-seconds' converts a number of seconds into a readable 1581*** `format-seconds' converts a number of seconds into a readable
1582string of days, hours, etc. 1582string of days, hours, etc.
1583 1583
1584+++
1584*** `apply-partially' performs a "curried" application of a function. 1585*** `apply-partially' performs a "curried" application of a function.
1585 1586
1586*** `read-shell-command' does what its name says, with completion. It 1587*** `read-shell-command' does what its name says, with completion. It