diff options
| author | Richard M. Stallman | 1994-04-29 10:07:31 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1994-04-29 10:07:31 +0000 |
| commit | f25df2ab1d2a3bb5b11c92c2c4c7d93ae489b889 (patch) | |
| tree | 6c2c1aa6c97f335a23b3a797ad9c2bcc0b9c4339 | |
| parent | 1d888548752f9c2b09ba31f411c70d3dea1fba17 (diff) | |
| download | emacs-f25df2ab1d2a3bb5b11c92c2c4c7d93ae489b889.tar.gz emacs-f25df2ab1d2a3bb5b11c92c2c4c7d93ae489b889.zip | |
entered into RCS
| -rw-r--r-- | lispref/functions.texi | 77 |
1 files changed, 44 insertions, 33 deletions
diff --git a/lispref/functions.texi b/lispref/functions.texi index 3897d02c06a..0f596cb6216 100644 --- a/lispref/functions.texi +++ b/lispref/functions.texi | |||
| @@ -190,8 +190,9 @@ the argument values are matched up against the variables in the lambda | |||
| 190 | list, which are given local bindings with the values provided. | 190 | list, which are given local bindings with the values provided. |
| 191 | @xref{Local Variables}. | 191 | @xref{Local Variables}. |
| 192 | 192 | ||
| 193 | The documentation string is an actual string that serves to describe | 193 | The documentation string is a Lisp string object placed within the |
| 194 | the function for the Emacs help facilities. @xref{Function Documentation}. | 194 | function definition to describe the function for the Emacs help |
| 195 | facilities. @xref{Function Documentation}. | ||
| 195 | 196 | ||
| 196 | The interactive declaration is a list of the form @code{(interactive | 197 | The interactive declaration is a list of the form @code{(interactive |
| 197 | @var{code-string})}. This declares how to provide arguments if the | 198 | @var{code-string})}. This declares how to provide arguments if the |
| @@ -245,8 +246,8 @@ this example: | |||
| 245 | 246 | ||
| 246 | @noindent | 247 | @noindent |
| 247 | This evaluates the arguments @code{1}, @code{(* 2 3)}, and @code{(- 5 | 248 | This evaluates the arguments @code{1}, @code{(* 2 3)}, and @code{(- 5 |
| 248 | 4)} from left to right. Then it applies the lambda expression applied | 249 | 4)} from left to right. Then it applies the lambda expression to the |
| 249 | to the argument values 1, 6 and 1 to produce the value 8. | 250 | argument values 1, 6 and 1 to produce the value 8. |
| 250 | 251 | ||
| 251 | It is not often useful to write a lambda expression as the @sc{car} of | 252 | It is not often useful to write a lambda expression as the @sc{car} of |
| 252 | a form in this way. You can get the same result, of making local | 253 | a form in this way. You can get the same result, of making local |
| @@ -277,7 +278,7 @@ arguments to be omitted. For example, the function @code{substring} | |||
| 277 | accepts three arguments---a string, the start index and the end | 278 | accepts three arguments---a string, the start index and the end |
| 278 | index---but the third argument defaults to the @var{length} of the | 279 | index---but the third argument defaults to the @var{length} of the |
| 279 | string if you omit it. It is also convenient for certain functions to | 280 | string if you omit it. It is also convenient for certain functions to |
| 280 | accept an indefinite number of arguments, as the functions @code{and} | 281 | accept an indefinite number of arguments, as the functions @code{list} |
| 281 | and @code{+} do. | 282 | and @code{+} do. |
| 282 | 283 | ||
| 283 | @cindex optional arguments | 284 | @cindex optional arguments |
| @@ -310,12 +311,12 @@ that unless the lambda list uses @code{&rest}. In that case, there may | |||
| 310 | be any number of extra actual arguments. | 311 | be any number of extra actual arguments. |
| 311 | 312 | ||
| 312 | If actual arguments for the optional and rest variables are omitted, | 313 | If actual arguments for the optional and rest variables are omitted, |
| 313 | then they always default to @code{nil}. However, the body of the function | 314 | then they always default to @code{nil}. There is no way for the |
| 314 | is free to consider @code{nil} an abbreviation for some other meaningful | ||
| 315 | value. This is what @code{substring} does; @code{nil} as the third argument | ||
| 316 | means to use the length of the string supplied. There is no way for the | ||
| 317 | function to distinguish between an explicit argument of @code{nil} and | 315 | function to distinguish between an explicit argument of @code{nil} and |
| 318 | an omitted argument. | 316 | an omitted argument. However, the body of the function is free to |
| 317 | consider @code{nil} an abbreviation for some other meaningful value. | ||
| 318 | This is what @code{substring} does; @code{nil} as the third argument to | ||
| 319 | @code{substring} means to use the length of the string supplied. | ||
| 319 | 320 | ||
| 320 | @cindex CL note---default optional arg | 321 | @cindex CL note---default optional arg |
| 321 | @quotation | 322 | @quotation |
| @@ -385,10 +386,10 @@ of one or two complete sentences that summarize the function's purpose. | |||
| 385 | The start of the documentation string is usually indented, but since | 386 | The start of the documentation string is usually indented, but since |
| 386 | these spaces come before the starting double-quote, they are not part of | 387 | these spaces come before the starting double-quote, they are not part of |
| 387 | the string. Some people make a practice of indenting any additional | 388 | the string. Some people make a practice of indenting any additional |
| 388 | lines of the string so that the text lines up. @emph{This is a | 389 | lines of the string so that the text lines up in the program source. |
| 389 | mistake.} The indentation of the following lines is inside the string; | 390 | @emph{This is a mistake.} The indentation of the following lines is |
| 390 | what looks nice in the source code will look ugly when displayed by the | 391 | inside the string; what looks nice in the source code will look ugly |
| 391 | help commands. | 392 | when displayed by the help commands. |
| 392 | 393 | ||
| 393 | You may wonder how the documentation string could be optional, since | 394 | You may wonder how the documentation string could be optional, since |
| 394 | there are required components of the function that follow it (the body). | 395 | there are required components of the function that follow it (the body). |
| @@ -530,9 +531,10 @@ deliberate redefinition from unintentional redefinition. | |||
| 530 | 531 | ||
| 531 | @defun defalias name definition | 532 | @defun defalias name definition |
| 532 | This special form defines the symbol @var{name} as a function, with | 533 | This special form defines the symbol @var{name} as a function, with |
| 533 | definition @var{definition}. It's best to use this rather than | 534 | definition @var{definition} (which can be any valid Lisp function). |
| 534 | @code{fset} when defining a function in a file, because @code{defalias} | 535 | It's best to use this rather than @code{fset} when defining a function |
| 535 | records which file defined the function (@pxref{Unloading}). | 536 | in a file, because @code{defalias} records which file defined the |
| 537 | function (@pxref{Unloading}), while @code{fset} does not. | ||
| 536 | @end defun | 538 | @end defun |
| 537 | 539 | ||
| 538 | @node Calling Functions | 540 | @node Calling Functions |
| @@ -544,9 +546,10 @@ records which file defined the function (@pxref{Unloading}). | |||
| 544 | anything until you @dfn{call} them, i.e., tell them to run. Calling a | 546 | anything until you @dfn{call} them, i.e., tell them to run. Calling a |
| 545 | function is also known as @dfn{invocation}. | 547 | function is also known as @dfn{invocation}. |
| 546 | 548 | ||
| 547 | The most common way of invoking a function is by evaluating a list. For | 549 | The most common way of invoking a function is by evaluating a list. |
| 548 | example, evaluating the list @code{(concat "a" "b")} calls the function | 550 | For example, evaluating the list @code{(concat "a" "b")} calls the |
| 549 | @code{concat}. @xref{Evaluation}, for a description of evaluation. | 551 | function @code{concat} with arguments @code{"a"} and @code{"b"}. |
| 552 | @xref{Evaluation}, for a description of evaluation. | ||
| 550 | 553 | ||
| 551 | When you write a list as an expression in your program, the function | 554 | When you write a list as an expression in your program, the function |
| 552 | name is part of the program. This means that you choose which function | 555 | name is part of the program. This means that you choose which function |
| @@ -600,8 +603,8 @@ Compare these example with the examples of @code{apply}. | |||
| 600 | @code{apply} calls @var{function} with @var{arguments}, just like | 603 | @code{apply} calls @var{function} with @var{arguments}, just like |
| 601 | @code{funcall} but with one difference: the last of @var{arguments} is a | 604 | @code{funcall} but with one difference: the last of @var{arguments} is a |
| 602 | list of arguments to give to @var{function}, rather than a single | 605 | list of arguments to give to @var{function}, rather than a single |
| 603 | argument. We also say that this list is @dfn{appended} to the other | 606 | argument. We also say that @code{apply} @dfn{spreads} this list so that |
| 604 | arguments. | 607 | each individual element becomes an argument. |
| 605 | 608 | ||
| 606 | @code{apply} returns the result of calling @var{function}. As with | 609 | @code{apply} returns the result of calling @var{function}. As with |
| 607 | @code{funcall}, @var{function} must either be a Lisp function or a | 610 | @code{funcall}, @var{function} must either be a Lisp function or a |
| @@ -665,10 +668,10 @@ here. For the third mapping function, @code{mapatoms}, see | |||
| 665 | @ref{Creating Symbols}. | 668 | @ref{Creating Symbols}. |
| 666 | 669 | ||
| 667 | @defun mapcar function sequence | 670 | @defun mapcar function sequence |
| 668 | @code{mapcar} applies @var{function} to each element of @var{sequence} in | 671 | @code{mapcar} applies @var{function} to each element of @var{sequence} |
| 669 | turn. The results are made into a @code{nil}-terminated list. | 672 | in turn, and returns a list of the results. |
| 670 | 673 | ||
| 671 | The argument @var{sequence} may be a list, a vector or a string. The | 674 | The argument @var{sequence} may be a list, a vector, or a string. The |
| 672 | result is always a list. The length of the result is the same as the | 675 | result is always a list. The length of the result is the same as the |
| 673 | length of @var{sequence}. | 676 | length of @var{sequence}. |
| 674 | 677 | ||
| @@ -857,6 +860,9 @@ realistic example using @code{function} and an anonymous function. | |||
| 857 | function cell of the symbol. The functions described here access, test, | 860 | function cell of the symbol. The functions described here access, test, |
| 858 | and set the function cell of symbols. | 861 | and set the function cell of symbols. |
| 859 | 862 | ||
| 863 | See also the function @code{indirect-function} in @ref{Function | ||
| 864 | Indirection}. | ||
| 865 | |||
| 860 | @defun symbol-function symbol | 866 | @defun symbol-function symbol |
| 861 | @kindex void-function | 867 | @kindex void-function |
| 862 | This returns the object in the function cell of @var{symbol}. If the | 868 | This returns the object in the function cell of @var{symbol}. If the |
| @@ -896,8 +902,7 @@ as a function, it signals a @code{void-function} error. | |||
| 896 | @code{void}. The symbols @code{nil} and @code{void} are Lisp objects, | 902 | @code{void}. The symbols @code{nil} and @code{void} are Lisp objects, |
| 897 | and can be stored into a function cell just as any other object can be | 903 | and can be stored into a function cell just as any other object can be |
| 898 | (and they can be valid functions if you define them in turn with | 904 | (and they can be valid functions if you define them in turn with |
| 899 | @code{defun}); but @code{nil} or @code{void} is @emph{an object}. A | 905 | @code{defun}). A void function cell contains no object whatsoever. |
| 900 | void function cell contains no object whatsoever. | ||
| 901 | 906 | ||
| 902 | You can test the voidness of a symbol's function definition with | 907 | You can test the voidness of a symbol's function definition with |
| 903 | @code{fboundp}. After you have given a symbol a function definition, you | 908 | @code{fboundp}. After you have given a symbol a function definition, you |
| @@ -920,6 +925,10 @@ error. (See also @code{makunbound}, in @ref{Local Variables}.) | |||
| 920 | @result{} x | 925 | @result{} x |
| 921 | @end group | 926 | @end group |
| 922 | @group | 927 | @group |
| 928 | (foo 1) | ||
| 929 | @result{}1 | ||
| 930 | @end group | ||
| 931 | @group | ||
| 923 | (fmakunbound 'foo) | 932 | (fmakunbound 'foo) |
| 924 | @result{} x | 933 | @result{} x |
| 925 | @end group | 934 | @end group |
| @@ -944,8 +953,10 @@ making an alternate name for a function.) | |||
| 944 | 953 | ||
| 945 | @item | 954 | @item |
| 946 | Giving a symbol a function definition that is not a list and therefore | 955 | Giving a symbol a function definition that is not a list and therefore |
| 947 | cannot be made with @code{defun}. @xref{Classifying Lists}, for an | 956 | cannot be made with @code{defun}. For example, you can use @code{fset} |
| 948 | example of this usage. | 957 | to give a symbol @code{s1} a function definition which is another symbol |
| 958 | @code{s2}; then @code{s1} serves as an alias for whatever definition | ||
| 959 | @code{s2} presently has. | ||
| 949 | 960 | ||
| 950 | @item | 961 | @item |
| 951 | In constructs for defining or altering functions. If @code{defun} | 962 | In constructs for defining or altering functions. If @code{defun} |
| @@ -990,6 +1001,9 @@ Here are examples of the first two uses: | |||
| 990 | @result{} "\^u2\^k" | 1001 | @result{} "\^u2\^k" |
| 991 | @end group | 1002 | @end group |
| 992 | @end example | 1003 | @end example |
| 1004 | |||
| 1005 | See also the related function @code{defalias}, in @ref{Defining | ||
| 1006 | Functions}. | ||
| 993 | @end defun | 1007 | @end defun |
| 994 | 1008 | ||
| 995 | When writing a function that extends a previously defined function, | 1009 | When writing a function that extends a previously defined function, |
| @@ -1013,9 +1027,6 @@ defines @code{foo} rather than @code{old-foo}, it does not produce the | |||
| 1013 | proper results. The only way to avoid this problem is to make sure the | 1027 | proper results. The only way to avoid this problem is to make sure the |
| 1014 | file is loaded before moving aside the old definition of @code{foo}. | 1028 | file is loaded before moving aside the old definition of @code{foo}. |
| 1015 | 1029 | ||
| 1016 | See also the function @code{indirect-function} in @ref{Function | ||
| 1017 | Indirection}. | ||
| 1018 | |||
| 1019 | @node Inline Functions | 1030 | @node Inline Functions |
| 1020 | @section Inline Functions | 1031 | @section Inline Functions |
| 1021 | @cindex inline functions | 1032 | @cindex inline functions |
| @@ -1049,7 +1060,7 @@ evaluated exactly once, you needn't worry about how many times the | |||
| 1049 | body uses the arguments, as you do for macros. (@xref{Argument | 1060 | body uses the arguments, as you do for macros. (@xref{Argument |
| 1050 | Evaluation}.) | 1061 | Evaluation}.) |
| 1051 | 1062 | ||
| 1052 | Inline functions can be used and open coded later on in the same file, | 1063 | Inline functions can be used and open-coded later on in the same file, |
| 1053 | following the definition, just like macros. | 1064 | following the definition, just like macros. |
| 1054 | 1065 | ||
| 1055 | Emacs versions prior to 19 did not have inline functions. | 1066 | Emacs versions prior to 19 did not have inline functions. |