Mercurial > hg > xemacs-beta
comparison man/lispref/functions.texi @ 5791:9fae6227ede5
Silence texinfo 5.2 warnings, primarily by adding next, prev, and up
pointers to all nodes. See xemacs-patches message with ID
<5315f7bf.sHpFD7lXYR05GH6E%james@xemacs.org>.
author | Jerry James <james@xemacs.org> |
---|---|
date | Thu, 27 Mar 2014 08:59:03 -0600 |
parents | 62b9ef1ed4ac |
children |
comparison
equal
deleted
inserted
replaced
5790:dcf9067f26bb | 5791:9fae6227ede5 |
---|---|
23 * Inline Functions:: Defining functions that the compiler will open code. | 23 * Inline Functions:: Defining functions that the compiler will open code. |
24 * Related Topics:: Cross-references to specific Lisp primitives | 24 * Related Topics:: Cross-references to specific Lisp primitives |
25 that have a special bearing on how functions work. | 25 that have a special bearing on how functions work. |
26 @end menu | 26 @end menu |
27 | 27 |
28 @node What Is a Function | 28 @node What Is a Function, Lambda Expressions, Functions and Commands, Functions and Commands |
29 @section What Is a Function? | 29 @section What Is a Function? |
30 | 30 |
31 In a general sense, a function is a rule for carrying on a computation | 31 In a general sense, a function is a rule for carrying on a computation |
32 given several values called @dfn{arguments}. The result of the | 32 given several values called @dfn{arguments}. The result of the |
33 computation is called the value of the function. The computation can | 33 computation is called the value of the function. The computation can |
148 @result{} t | 148 @result{} t |
149 @end group | 149 @end group |
150 @end example | 150 @end example |
151 @end defun | 151 @end defun |
152 | 152 |
153 @node Lambda Expressions | 153 @node Lambda Expressions, Function Names, What Is a Function, Functions and Commands |
154 @section Lambda Expressions | 154 @section Lambda Expressions |
155 @cindex lambda expression | 155 @cindex lambda expression |
156 | 156 |
157 A function written in Lisp is a list that looks like this: | 157 A function written in Lisp is a list that looks like this: |
158 | 158 |
175 * Simple Lambda:: A simple example. | 175 * Simple Lambda:: A simple example. |
176 * Argument List:: Details and special features of argument lists. | 176 * Argument List:: Details and special features of argument lists. |
177 * Function Documentation:: How to put documentation in a function. | 177 * Function Documentation:: How to put documentation in a function. |
178 @end menu | 178 @end menu |
179 | 179 |
180 @node Lambda Components | 180 @node Lambda Components, Simple Lambda, Lambda Expressions, Lambda Expressions |
181 @subsection Components of a Lambda Expression | 181 @subsection Components of a Lambda Expression |
182 | 182 |
183 @ifinfo | 183 @ifinfo |
184 | 184 |
185 A function written in Lisp (a ``lambda expression'') is a list that | 185 A function written in Lisp (a ``lambda expression'') is a list that |
222 The rest of the elements are the @dfn{body} of the function: the Lisp | 222 The rest of the elements are the @dfn{body} of the function: the Lisp |
223 code to do the work of the function (or, as a Lisp programmer would say, | 223 code to do the work of the function (or, as a Lisp programmer would say, |
224 ``a list of Lisp forms to evaluate''). The value returned by the | 224 ``a list of Lisp forms to evaluate''). The value returned by the |
225 function is the value returned by the last element of the body. | 225 function is the value returned by the last element of the body. |
226 | 226 |
227 @node Simple Lambda | 227 @node Simple Lambda, Argument List, Lambda Components, Lambda Expressions |
228 @subsection A Simple Lambda-Expression Example | 228 @subsection A Simple Lambda-Expression Example |
229 | 229 |
230 Consider for example the following function: | 230 Consider for example the following function: |
231 | 231 |
232 @example | 232 @example |
276 However, calls to explicit lambda expressions were very useful in the | 276 However, calls to explicit lambda expressions were very useful in the |
277 old days of Lisp, before the special operator @code{let} was invented. At | 277 old days of Lisp, before the special operator @code{let} was invented. At |
278 that time, they were the only way to bind and initialize local | 278 that time, they were the only way to bind and initialize local |
279 variables. | 279 variables. |
280 | 280 |
281 @node Argument List | 281 @node Argument List, Function Documentation, Simple Lambda, Lambda Expressions |
282 @subsection Advanced Features of Argument Lists | 282 @subsection Advanced Features of Argument Lists |
283 @kindex wrong-number-of-arguments | 283 @kindex wrong-number-of-arguments |
284 @cindex argument binding | 284 @cindex argument binding |
285 @cindex binding arguments | 285 @cindex binding arguments |
286 | 286 |
378 (+ n (apply '+ ns))) ; @r{1 or more arguments.} | 378 (+ n (apply '+ ns))) ; @r{1 or more arguments.} |
379 1 2 3 4 5) | 379 1 2 3 4 5) |
380 @result{} 15 | 380 @result{} 15 |
381 @end smallexample | 381 @end smallexample |
382 | 382 |
383 @node Function Documentation | 383 @node Function Documentation, , Argument List, Lambda Expressions |
384 @subsection Documentation Strings of Functions | 384 @subsection Documentation Strings of Functions |
385 @cindex documentation of function | 385 @cindex documentation of function |
386 | 386 |
387 A lambda expression may optionally have a @dfn{documentation string} just | 387 A lambda expression may optionally have a @dfn{documentation string} just |
388 after the lambda list. This string does not affect execution of the | 388 after the lambda list. This string does not affect execution of the |
414 it has no effect if it is not the last form in the body. Thus, in | 414 it has no effect if it is not the last form in the body. Thus, in |
415 practice, there is no confusion between the first form of the body and the | 415 practice, there is no confusion between the first form of the body and the |
416 documentation string; if the only body form is a string then it serves both | 416 documentation string; if the only body form is a string then it serves both |
417 as the return value and as the documentation. | 417 as the return value and as the documentation. |
418 | 418 |
419 @node Function Names | 419 @node Function Names, Defining Functions, Lambda Expressions, Functions and Commands |
420 @section Naming a Function | 420 @section Naming a Function |
421 @cindex function definition | 421 @cindex function definition |
422 @cindex named function | 422 @cindex named function |
423 @cindex function name | 423 @cindex function name |
424 | 424 |
465 equally well a name for the same function. | 465 equally well a name for the same function. |
466 | 466 |
467 A symbol used as a function name may also be used as a variable; | 467 A symbol used as a function name may also be used as a variable; |
468 these two uses of a symbol are independent and do not conflict. | 468 these two uses of a symbol are independent and do not conflict. |
469 | 469 |
470 @node Defining Functions | 470 @node Defining Functions, Calling Functions, Function Names, Functions and Commands |
471 @section Defining Functions | 471 @section Defining Functions |
472 @cindex defining a function | 472 @cindex defining a function |
473 | 473 |
474 We usually give a name to a function when it is first created. This | 474 We usually give a name to a function when it is first created. This |
475 is called @dfn{defining a function}, and it is done with the | 475 is called @dfn{defining a function}, and it is done with the |
565 @end defun | 565 @end defun |
566 | 566 |
567 See also @code{defsubst}, which defines a function like @code{defun} | 567 See also @code{defsubst}, which defines a function like @code{defun} |
568 and tells the Lisp compiler to open-code it. @xref{Inline Functions}. | 568 and tells the Lisp compiler to open-code it. @xref{Inline Functions}. |
569 | 569 |
570 @node Calling Functions | 570 @node Calling Functions, Mapping Functions, Defining Functions, Functions and Commands |
571 @section Calling Functions | 571 @section Calling Functions |
572 @cindex function invocation | 572 @cindex function invocation |
573 @cindex calling a function | 573 @cindex calling a function |
574 | 574 |
575 Defining functions is only half the battle. Functions don't do | 575 Defining functions is only half the battle. Functions don't do |
685 | 685 |
686 @deffn Command ignore &rest args | 686 @deffn Command ignore &rest args |
687 This function ignores any arguments and returns @code{nil}. | 687 This function ignores any arguments and returns @code{nil}. |
688 @end deffn | 688 @end deffn |
689 | 689 |
690 @node Mapping Functions | 690 @node Mapping Functions, Anonymous Functions, Calling Functions, Functions and Commands |
691 @section Mapping Functions | 691 @section Mapping Functions |
692 @cindex mapping functions | 692 @cindex mapping functions |
693 | 693 |
694 A @dfn{mapping function} applies a given function to each element of a | 694 A @dfn{mapping function} applies a given function to each element of a |
695 list or other collection. XEmacs Lisp has several such functions; | 695 list or other collection. XEmacs Lisp has several such functions; |
771 @result{} "IBM.9111" | 771 @result{} "IBM.9111" |
772 @end group | 772 @end group |
773 @end smallexample | 773 @end smallexample |
774 @end defun | 774 @end defun |
775 | 775 |
776 @node Anonymous Functions | 776 @node Anonymous Functions, Function Cells, Mapping Functions, Functions and Commands |
777 @section Anonymous Functions | 777 @section Anonymous Functions |
778 @cindex anonymous function | 778 @cindex anonymous function |
779 | 779 |
780 In Lisp, a function is a list that starts with @code{lambda}, a | 780 In Lisp, a function is a list that starts with @code{lambda}, a |
781 byte-code function compiled from such a list, or alternatively a | 781 byte-code function compiled from such a list, or alternatively a |
885 @end example | 885 @end example |
886 | 886 |
887 See @code{documentation} in @ref{Accessing Documentation}, for a | 887 See @code{documentation} in @ref{Accessing Documentation}, for a |
888 realistic example using @code{function} and an anonymous function. | 888 realistic example using @code{function} and an anonymous function. |
889 | 889 |
890 @node Function Cells | 890 @node Function Cells, Inline Functions, Anonymous Functions, Functions and Commands |
891 @section Accessing Function Cell Contents | 891 @section Accessing Function Cell Contents |
892 | 892 |
893 The @dfn{function definition} of a symbol is the object stored in the | 893 The @dfn{function definition} of a symbol is the object stored in the |
894 function cell of the symbol. The functions described here access, test, | 894 function cell of the symbol. The functions described here access, test, |
895 and set the function cell of symbols. | 895 and set the function cell of symbols. |
1062 file is loaded before moving aside the old definition of @code{foo}. | 1062 file is loaded before moving aside the old definition of @code{foo}. |
1063 | 1063 |
1064 But it is unmodular and unclean, in any case, for a Lisp file to | 1064 But it is unmodular and unclean, in any case, for a Lisp file to |
1065 redefine a function defined elsewhere. | 1065 redefine a function defined elsewhere. |
1066 | 1066 |
1067 @node Inline Functions | 1067 @node Inline Functions, Related Topics, Function Cells, Functions and Commands |
1068 @section Inline Functions | 1068 @section Inline Functions |
1069 @cindex inline functions | 1069 @cindex inline functions |
1070 | 1070 |
1071 @findex defsubst | 1071 @findex defsubst |
1072 You can define an @dfn{inline function} by using @code{defsubst} instead | 1072 You can define an @dfn{inline function} by using @code{defsubst} instead |
1100 Inline functions can be used and open-coded later on in the same file, | 1100 Inline functions can be used and open-coded later on in the same file, |
1101 following the definition, just like macros. | 1101 following the definition, just like macros. |
1102 | 1102 |
1103 @c Emacs versions prior to 19 did not have inline functions. | 1103 @c Emacs versions prior to 19 did not have inline functions. |
1104 | 1104 |
1105 @node Related Topics | 1105 @node Related Topics, , Inline Functions, Functions and Commands |
1106 @section Other Topics Related to Functions | 1106 @section Other Topics Related to Functions |
1107 | 1107 |
1108 Here is a table of several functions that do things related to | 1108 Here is a table of several functions that do things related to |
1109 function calling and function definitions. They are documented | 1109 function calling and function definitions. They are documented |
1110 elsewhere, but we provide cross references here. | 1110 elsewhere, but we provide cross references here. |