[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] Changes to emacs/doc/lispref/functions.texi,v
From: |
Eli Zaretskii |
Subject: |
[Emacs-diffs] Changes to emacs/doc/lispref/functions.texi,v |
Date: |
Sun, 19 Oct 2008 14:56:28 +0000 |
CVSROOT: /cvsroot/emacs
Module name: emacs
Changes by: Eli Zaretskii <eliz> 08/10/19 14:56:28
Index: functions.texi
===================================================================
RCS file: /cvsroot/emacs/emacs/doc/lispref/functions.texi,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- functions.texi 13 Oct 2008 11:18:02 -0000 1.12
+++ functions.texi 19 Oct 2008 14:56:27 -0000 1.13
@@ -725,6 +725,41 @@
of mapcar}.
@end defun
address@hidden partial application of functions
address@hidden currying
+ Sometimes, it is useful to fix some of the function's arguments at
+certain values, and leave the rest of arguments for when the function
+is actually called. The act of fixing some of the function's
+arguments is called @dfn{partial application} of the address@hidden
+This is related to, but different from @dfn{currying}, which
+transforms a function that takes multiple arguments in such a way that
+it can be called as a chain of functions, each one with a single
+argument.}.
+The result is a new function that accepts the rest of
+arguments and calls the original function with all the arguments
+combined. Emacs provides a function for partial evaluation:
+
address@hidden apply-partially func &rest args
+This function returns a new function which, when called, will call
address@hidden with the list of arguments composed from @var{args} and
+additional arguments specified at the time of the call. If @var{func}
+accepts @var{n} arguments, then a call to @code{apply-partially} with
address@hidden@address@hidden < @var{n}}} arguments will produce a new function
of
address@hidden@address@hidden - @var{m}}} arguments.
+
+Here's an example of using @code{apply-partially} to produce a
+function @code{incr}, that will increment its argument by one, based
+on the Emacs Lisp primitive @code{+}:
+
address@hidden
+(fset 'incr (apply-partially '+ 1))
address@hidden
+(incr 10)
+ @result{} 11
address@hidden group
address@hidden example
address@hidden defun
+
@cindex functionals
It is common for Lisp functions to accept functions as arguments or
find them in data structures (especially in hook variables and property