aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorStefan Monnier2010-06-13 16:36:17 -0400
committerStefan Monnier2010-06-13 16:36:17 -0400
commitb9598260f96ddc652cd82ab64bbe922ccfc48a29 (patch)
tree2a692a8471de07f2578ea481c99971585def8eda /doc
parenta6e8d97c1414230e577d375c27da78c858a5fa75 (diff)
downloademacs-b9598260f96ddc652cd82ab64bbe922ccfc48a29.tar.gz
emacs-b9598260f96ddc652cd82ab64bbe922ccfc48a29.zip
New branch for lexbind, losing all history.
This initial patch is based on 2002-06-27T22:39:10Z!storm@cua.dk of the original lexbind branch.
Diffstat (limited to 'doc')
-rw-r--r--doc/lispref/elisp.texi7
-rw-r--r--doc/lispref/functions.texi72
-rw-r--r--doc/lispref/objects.texi61
-rw-r--r--doc/lispref/vol1.texi2
-rw-r--r--doc/lispref/vol2.texi2
5 files changed, 125 insertions, 19 deletions
diff --git a/doc/lispref/elisp.texi b/doc/lispref/elisp.texi
index 0f746187212..46d242fcfba 100644
--- a/doc/lispref/elisp.texi
+++ b/doc/lispref/elisp.texi
@@ -248,7 +248,7 @@ Programming Types
248* Macro Type:: A method of expanding an expression into another 248* Macro Type:: A method of expanding an expression into another
249 expression, more fundamental but less pretty. 249 expression, more fundamental but less pretty.
250* Primitive Function Type:: A function written in C, callable from Lisp. 250* Primitive Function Type:: A function written in C, callable from Lisp.
251* Byte-Code Type:: A function written in Lisp, then compiled. 251* Funvec Type:: A vector type callable as a function.
252* Autoload Type:: A type used for automatically loading seldom-used 252* Autoload Type:: A type used for automatically loading seldom-used
253 functions. 253 functions.
254 254
@@ -463,10 +463,11 @@ Functions
463* Inline Functions:: Defining functions that the compiler 463* Inline Functions:: Defining functions that the compiler
464 will open code. 464 will open code.
465* Declaring Functions:: Telling the compiler that a function is defined. 465* Declaring Functions:: Telling the compiler that a function is defined.
466* Function Currying:: Making wrapper functions that pre-specify
467 some arguments.
466* Function Safety:: Determining whether a function is safe to call. 468* Function Safety:: Determining whether a function is safe to call.
467* Related Topics:: Cross-references to specific Lisp primitives 469* Related Topics:: Cross-references to specific Lisp primitives
468 that have a special bearing on how 470 that have a special bearing on how functions work.
469 functions work.
470 471
471Lambda Expressions 472Lambda Expressions
472 473
diff --git a/doc/lispref/functions.texi b/doc/lispref/functions.texi
index 37e8726592a..7e8ac09b44e 100644
--- a/doc/lispref/functions.texi
+++ b/doc/lispref/functions.texi
@@ -22,7 +22,9 @@ define them.
22* Function Cells:: Accessing or setting the function definition 22* Function Cells:: Accessing or setting the function definition
23 of a symbol. 23 of a symbol.
24* Obsolete Functions:: Declaring functions obsolete. 24* Obsolete Functions:: Declaring functions obsolete.
25* Inline Functions:: Defining functions that the compiler will open code. 25* Inline Functions:: Defining functions that the compiler will open code.
26* Function Currying:: Making wrapper functions that pre-specify
27 some arguments.
26* Declaring Functions:: Telling the compiler that a function is defined. 28* Declaring Functions:: Telling the compiler that a function is defined.
27* Function Safety:: Determining whether a function is safe to call. 29* Function Safety:: Determining whether a function is safe to call.
28* Related Topics:: Cross-references to specific Lisp primitives 30* Related Topics:: Cross-references to specific Lisp primitives
@@ -111,7 +113,25 @@ editors; for Lisp programs, the distinction is normally unimportant.
111 113
112@item byte-code function 114@item byte-code function
113A @dfn{byte-code function} is a function that has been compiled by the 115A @dfn{byte-code function} is a function that has been compiled by the
114byte compiler. @xref{Byte-Code Type}. 116byte compiler. A byte-code function is actually a special case of a
117@dfn{funvec} object (see below).
118
119@item function vector
120A @dfn{function vector}, or @dfn{funvec} is a vector-like object whose
121purpose is to define special kinds of functions. @xref{Funvec Type}.
122
123The exact meaning of the vector elements is determined by the type of
124funvec: the most common use is byte-code functions, which have a
125list---the argument list---as the first element. Further types of
126funvec object are:
127
128@table @code
129@item curry
130A curried function. Remaining arguments in the funvec are function to
131call, and arguments to prepend to user arguments at the time of the
132call; @xref{Function Currying}.
133@end table
134
115@end table 135@end table
116 136
117@defun functionp object 137@defun functionp object
@@ -152,6 +172,11 @@ function. For example:
152@end example 172@end example
153@end defun 173@end defun
154 174
175@defun funvecp object
176@code{funvecp} returns @code{t} if @var{object} is a function vector
177object (including byte-code objects), and @code{nil} otherwise.
178@end defun
179
155@defun subr-arity subr 180@defun subr-arity subr
156This function provides information about the argument list of a 181This function provides information about the argument list of a
157primitive, @var{subr}. The returned value is a pair 182primitive, @var{subr}. The returned value is a pair
@@ -1277,6 +1302,49 @@ do for macros. (@xref{Argument Evaluation}.)
1277Inline functions can be used and open-coded later on in the same file, 1302Inline functions can be used and open-coded later on in the same file,
1278following the definition, just like macros. 1303following the definition, just like macros.
1279 1304
1305@node Function Currying
1306@section Function Currying
1307@cindex function currying
1308@cindex currying
1309@cindex partial-application
1310
1311Function currying is a way to make a new function that calls an
1312existing function with a partially pre-determined argument list.
1313
1314@defun curry function &rest args
1315Return a function-like object that will append any arguments it is
1316called with to @var{args}, and call @var{function} with the resulting
1317list of arguments.
1318
1319For example, @code{(curry 'concat "The ")} returns a function that
1320concatenates @code{"The "} and its arguments. Calling this function
1321on @code{"end"} returns @code{"The end"}:
1322
1323@example
1324(funcall (curry 'concat "The ") "end")
1325 @result{} "The end"
1326@end example
1327
1328The @dfn{curried function} is useful as an argument to @code{mapcar}:
1329
1330@example
1331(mapcar (curry 'concat "The ") '("big" "red" "balloon"))
1332 @result{} ("The big" "The red" "The balloon")
1333@end example
1334@end defun
1335
1336Function currying may be implemented in any Lisp by constructing a
1337@code{lambda} expression, for instance:
1338
1339@example
1340(defun curry (function &rest args)
1341 `(lambda (&rest call-args)
1342 (apply #',function ,@@args call-args)))
1343@end example
1344
1345However in Emacs Lisp, a special curried function object is used for
1346efficiency. @xref{Funvec Type}.
1347
1280@node Declaring Functions 1348@node Declaring Functions
1281@section Telling the Compiler that a Function is Defined 1349@section Telling the Compiler that a Function is Defined
1282@cindex function declaration 1350@cindex function declaration
diff --git a/doc/lispref/objects.texi b/doc/lispref/objects.texi
index 5c3ac13cdaf..1a72fdf671c 100644
--- a/doc/lispref/objects.texi
+++ b/doc/lispref/objects.texi
@@ -157,7 +157,7 @@ latter are unique to Emacs Lisp.
157* Macro Type:: A method of expanding an expression into another 157* Macro Type:: A method of expanding an expression into another
158 expression, more fundamental but less pretty. 158 expression, more fundamental but less pretty.
159* Primitive Function Type:: A function written in C, callable from Lisp. 159* Primitive Function Type:: A function written in C, callable from Lisp.
160* Byte-Code Type:: A function written in Lisp, then compiled. 160* Funvec Type:: A vector type callable as a function.
161* Autoload Type:: A type used for automatically loading seldom-used 161* Autoload Type:: A type used for automatically loading seldom-used
162 functions. 162 functions.
163@end menu 163@end menu
@@ -1315,18 +1315,55 @@ with the name of the subroutine.
1315@end group 1315@end group
1316@end example 1316@end example
1317 1317
1318@node Byte-Code Type 1318@node Funvec Type
1319@subsection Byte-Code Function Type 1319@subsection ``Function Vector' Type
1320@cindex function vector
1321@cindex funvec
1320 1322
1321The byte compiler produces @dfn{byte-code function objects}. 1323A @dfn{function vector}, or @dfn{funvec} is a vector-like object whose
1322Internally, a byte-code function object is much like a vector; however, 1324purpose is to define special kinds of functions. You can examine or
1323the evaluator handles this data type specially when it appears as a 1325modify the contents of a funvec like a normal vector, using the
1324function to be called. @xref{Byte Compilation}, for information about 1326@code{aref} and @code{aset} functions.
1325the byte compiler.
1326 1327
1327The printed representation and read syntax for a byte-code function 1328The behavior of a funvec when called is dependent on the kind of
1328object is like that for a vector, with an additional @samp{#} before the 1329funvec it is, and that is determined by its first element (a
1329opening @samp{[}. 1330zero-length funvec will signal an error if called):
1331
1332@table @asis
1333@item A list
1334A funvec with a list as its first element is a byte-compiled function,
1335produced by the byte compiler; such funvecs are known as
1336@dfn{byte-code function objects}. @xref{Byte Compilation}, for
1337information about the byte compiler.
1338
1339@item The symbol @code{curry}
1340A funvec with @code{curry} as its first element is a ``curried function''.
1341
1342The second element in such a funvec is the function which is
1343being curried, and the remaining elements are a list of arguments.
1344
1345Calling such a funvec operates by calling the embedded function with
1346an argument list composed of the arguments in the funvec followed by
1347the arguments the funvec was called with. @xref{Function Currying}.
1348@end table
1349
1350The printed representation and read syntax for a funvec object is like
1351that for a vector, with an additional @samp{#} before the opening
1352@samp{[}.
1353
1354@defun funvecp object
1355@code{funvecp} returns @code{t} if @var{object} is a function vector
1356object (including byte-code objects), and @code{nil} otherwise.
1357@end defun
1358
1359@defun funvec kind &rest params
1360@code{funvec} returns a new function vector containing @var{kind} and
1361@var{params}. @var{kind} determines the type of funvec; it should be
1362one of the choices listed in the table above.
1363
1364Typically you should use the @code{make-byte-code} function to create
1365byte-code objects, though they are a type of funvec.
1366@end defun
1330 1367
1331@node Autoload Type 1368@node Autoload Type
1332@subsection Autoload Type 1369@subsection Autoload Type
@@ -1773,7 +1810,7 @@ with references to further information.
1773@xref{Buffer Basics, bufferp}. 1810@xref{Buffer Basics, bufferp}.
1774 1811
1775@item byte-code-function-p 1812@item byte-code-function-p
1776@xref{Byte-Code Type, byte-code-function-p}. 1813@xref{Funvec Type, byte-code-function-p}.
1777 1814
1778@item case-table-p 1815@item case-table-p
1779@xref{Case Tables, case-table-p}. 1816@xref{Case Tables, case-table-p}.
diff --git a/doc/lispref/vol1.texi b/doc/lispref/vol1.texi
index a0590c3d282..052d83eacd7 100644
--- a/doc/lispref/vol1.texi
+++ b/doc/lispref/vol1.texi
@@ -268,7 +268,7 @@ Programming Types
268* Macro Type:: A method of expanding an expression into another 268* Macro Type:: A method of expanding an expression into another
269 expression, more fundamental but less pretty. 269 expression, more fundamental but less pretty.
270* Primitive Function Type:: A function written in C, callable from Lisp. 270* Primitive Function Type:: A function written in C, callable from Lisp.
271* Byte-Code Type:: A function written in Lisp, then compiled. 271* Funvec Type:: A vector type callable as a function.
272* Autoload Type:: A type used for automatically loading seldom-used 272* Autoload Type:: A type used for automatically loading seldom-used
273 functions. 273 functions.
274 274
diff --git a/doc/lispref/vol2.texi b/doc/lispref/vol2.texi
index ad4c74611a8..d6358f3ecfc 100644
--- a/doc/lispref/vol2.texi
+++ b/doc/lispref/vol2.texi
@@ -267,7 +267,7 @@ Programming Types
267* Macro Type:: A method of expanding an expression into another 267* Macro Type:: A method of expanding an expression into another
268 expression, more fundamental but less pretty. 268 expression, more fundamental but less pretty.
269* Primitive Function Type:: A function written in C, callable from Lisp. 269* Primitive Function Type:: A function written in C, callable from Lisp.
270* Byte-Code Type:: A function written in Lisp, then compiled. 270* Funvec Type:: A vector type callable as a function.
271* Autoload Type:: A type used for automatically loading seldom-used 271* Autoload Type:: A type used for automatically loading seldom-used
272 functions. 272 functions.
273 273