21 |
* Anonymous Functions:: Lambda expressions are functions with no names. |
* Anonymous Functions:: Lambda expressions are functions with no names. |
22 |
* Function Cells:: Accessing or setting the function definition |
* Function Cells:: Accessing or setting the function definition |
23 |
of a symbol. |
of a symbol. |
24 |
* Inline Functions:: Defining functions that the compiler will open code. |
* Inline Functions:: Defining functions that the compiler will open code. |
25 |
|
* Function Currying:: Making wrapper functions that pre-specify |
26 |
|
some arguments. |
27 |
* Function Safety:: Determining whether a function is safe to call. |
* Function Safety:: Determining whether a function is safe to call. |
28 |
* Related Topics:: Cross-references to specific Lisp primitives |
* Related Topics:: Cross-references to specific Lisp primitives |
29 |
that have a special bearing on how functions work. |
that have a special bearing on how functions work. |
111 |
|
|
112 |
@item byte-code function |
@item byte-code function |
113 |
A @dfn{byte-code function} is a function that has been compiled by the |
A @dfn{byte-code function} is a function that has been compiled by the |
114 |
byte compiler. @xref{Byte-Code Type}. |
byte compiler. A byte-code function is actually a special case of a |
115 |
|
@dfn{funvec} object (see below). |
116 |
|
|
117 |
|
@item function vector |
118 |
|
A @dfn{function vector}, or @dfn{funvec} is a vector-like object whose |
119 |
|
purpose is to define special kinds of functions. @xref{Funvec Type}. |
120 |
|
|
121 |
|
The exact meaning of the vector elements is determined by the type of |
122 |
|
funvec: the most common use is byte-code functions, which have a |
123 |
|
list---the argument list---as the first element. Further types of |
124 |
|
funvec object are: |
125 |
|
|
126 |
|
@table @code |
127 |
|
@item curry |
128 |
|
A curried function. Remaining arguments in the funvec are function to |
129 |
|
call, and arguments to prepend to user arguments at the time of the |
130 |
|
call; @xref{Function Currying}. |
131 |
|
@end table |
132 |
|
|
133 |
@end table |
@end table |
134 |
|
|
135 |
@defun functionp object |
@defun functionp object |
170 |
@end example |
@end example |
171 |
@end defun |
@end defun |
172 |
|
|
173 |
|
@defun funvecp object |
174 |
|
@code{funvecp} returns @code{t} if @var{object} is a function vector |
175 |
|
object (including byte-code objects), and @code{nil} otherwise. |
176 |
|
@end defun |
177 |
|
|
178 |
@defun subr-arity subr |
@defun subr-arity subr |
179 |
@tindex subr-arity |
@tindex subr-arity |
180 |
This function provides information about the argument list of a |
This function provides information about the argument list of a |
1222 |
Inline functions can be used and open-coded later on in the same file, |
Inline functions can be used and open-coded later on in the same file, |
1223 |
following the definition, just like macros. |
following the definition, just like macros. |
1224 |
|
|
1225 |
|
@node Function Currying |
1226 |
|
@section Function Currying |
1227 |
|
@cindex function currying |
1228 |
|
@cindex currying |
1229 |
|
@cindex partial-application |
1230 |
|
|
1231 |
|
Function currying is a way to make a new function that calls an |
1232 |
|
existing function with a partially pre-determined argument list. |
1233 |
|
|
1234 |
|
@defun curry function &rest args |
1235 |
|
Return a function-like object that will append any arguments it is |
1236 |
|
called with to @var{args}, and call @var{function} with the resulting |
1237 |
|
list of arguments. |
1238 |
|
|
1239 |
|
For example, @code{(curry 'concat "The ")} returns a function that |
1240 |
|
concatenates @code{"The "} and its arguments. Calling this function |
1241 |
|
on @code{"end"} returns @code{"The end"}: |
1242 |
|
|
1243 |
|
@example |
1244 |
|
(funcall (curry 'concat "The ") "end") |
1245 |
|
@result{} "The end" |
1246 |
|
@end example |
1247 |
|
|
1248 |
|
The @dfn{curried function} is useful as an argument to @code{mapcar}: |
1249 |
|
|
1250 |
|
@example |
1251 |
|
(mapcar (curry 'concat "The ") '("big" "red" "balloon")) |
1252 |
|
@result{} ("The big" "The red" "The balloon") |
1253 |
|
@end example |
1254 |
|
@end defun |
1255 |
|
|
1256 |
|
Function currying may be implemented in any Lisp by constructing a |
1257 |
|
@code{lambda} expression, for instance: |
1258 |
|
|
1259 |
|
@example |
1260 |
|
(defun curry (function &rest args) |
1261 |
|
`(lambda (&rest call-args) |
1262 |
|
(apply #',function ,@@args call-args))) |
1263 |
|
@end example |
1264 |
|
|
1265 |
|
However in Emacs Lisp, a special curried function object is used for |
1266 |
|
efficiency. @xref{Funvec Type}. |
1267 |
|
|
1268 |
@node Function Safety |
@node Function Safety |
1269 |
@section Determining whether a function is safe to call |
@section Determining whether a function is safe to call |
1270 |
@cindex function safety |
@cindex function safety |