aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1994-04-29 10:07:31 +0000
committerRichard M. Stallman1994-04-29 10:07:31 +0000
commitf25df2ab1d2a3bb5b11c92c2c4c7d93ae489b889 (patch)
tree6c2c1aa6c97f335a23b3a797ad9c2bcc0b9c4339
parent1d888548752f9c2b09ba31f411c70d3dea1fba17 (diff)
downloademacs-f25df2ab1d2a3bb5b11c92c2c4c7d93ae489b889.tar.gz
emacs-f25df2ab1d2a3bb5b11c92c2c4c7d93ae489b889.zip
entered into RCS
-rw-r--r--lispref/functions.texi77
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
190list, which are given local bindings with the values provided. 190list, 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
194the function for the Emacs help facilities. @xref{Function Documentation}. 194function definition to describe the function for the Emacs help
195facilities. @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
247This evaluates the arguments @code{1}, @code{(* 2 3)}, and @code{(- 5 248This evaluates the arguments @code{1}, @code{(* 2 3)}, and @code{(- 5
2484)} from left to right. Then it applies the lambda expression applied 2494)} from left to right. Then it applies the lambda expression to the
249to the argument values 1, 6 and 1 to produce the value 8. 250argument 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
252a form in this way. You can get the same result, of making local 253a 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}
277accepts three arguments---a string, the start index and the end 278accepts three arguments---a string, the start index and the end
278index---but the third argument defaults to the @var{length} of the 279index---but the third argument defaults to the @var{length} of the
279string if you omit it. It is also convenient for certain functions to 280string if you omit it. It is also convenient for certain functions to
280accept an indefinite number of arguments, as the functions @code{and} 281accept an indefinite number of arguments, as the functions @code{list}
281and @code{+} do. 282and @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
310be any number of extra actual arguments. 311be 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,
313then they always default to @code{nil}. However, the body of the function 314then they always default to @code{nil}. There is no way for the
314is free to consider @code{nil} an abbreviation for some other meaningful
315value. This is what @code{substring} does; @code{nil} as the third argument
316means to use the length of the string supplied. There is no way for the
317function to distinguish between an explicit argument of @code{nil} and 315function to distinguish between an explicit argument of @code{nil} and
318an omitted argument. 316an omitted argument. However, the body of the function is free to
317consider @code{nil} an abbreviation for some other meaningful value.
318This 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
386these spaces come before the starting double-quote, they are not part of 387these spaces come before the starting double-quote, they are not part of
387the string. Some people make a practice of indenting any additional 388the string. Some people make a practice of indenting any additional
388lines of the string so that the text lines up. @emph{This is a 389lines of the string so that the text lines up in the program source.
389mistake.} The indentation of the following lines is inside the string; 390@emph{This is a mistake.} The indentation of the following lines is
390what looks nice in the source code will look ugly when displayed by the 391inside the string; what looks nice in the source code will look ugly
391help commands. 392when 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
394there are required components of the function that follow it (the body). 395there 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
532This special form defines the symbol @var{name} as a function, with 533This special form defines the symbol @var{name} as a function, with
533definition @var{definition}. It's best to use this rather than 534definition @var{definition} (which can be any valid Lisp function).
534@code{fset} when defining a function in a file, because @code{defalias} 535It's best to use this rather than @code{fset} when defining a function
535records which file defined the function (@pxref{Unloading}). 536in a file, because @code{defalias} records which file defined the
537function (@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}).
544anything until you @dfn{call} them, i.e., tell them to run. Calling a 546anything until you @dfn{call} them, i.e., tell them to run. Calling a
545function is also known as @dfn{invocation}. 547function 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.
548example, evaluating the list @code{(concat "a" "b")} calls the function 550For example, evaluating the list @code{(concat "a" "b")} calls the
549@code{concat}. @xref{Evaluation}, for a description of evaluation. 551function @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
552name is part of the program. This means that you choose which function 555name 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
602list of arguments to give to @var{function}, rather than a single 605list of arguments to give to @var{function}, rather than a single
603argument. We also say that this list is @dfn{appended} to the other 606argument. We also say that @code{apply} @dfn{spreads} this list so that
604arguments. 607each 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}
669turn. The results are made into a @code{nil}-terminated list. 672in turn, and returns a list of the results.
670 673
671The argument @var{sequence} may be a list, a vector or a string. The 674The argument @var{sequence} may be a list, a vector, or a string. The
672result is always a list. The length of the result is the same as the 675result is always a list. The length of the result is the same as the
673length of @var{sequence}. 676length of @var{sequence}.
674 677
@@ -857,6 +860,9 @@ realistic example using @code{function} and an anonymous function.
857function cell of the symbol. The functions described here access, test, 860function cell of the symbol. The functions described here access, test,
858and set the function cell of symbols. 861and set the function cell of symbols.
859 862
863 See also the function @code{indirect-function} in @ref{Function
864Indirection}.
865
860@defun symbol-function symbol 866@defun symbol-function symbol
861@kindex void-function 867@kindex void-function
862This returns the object in the function cell of @var{symbol}. If the 868This 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,
897and can be stored into a function cell just as any other object can be 903and 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.
900void 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
946Giving a symbol a function definition that is not a list and therefore 955Giving a symbol a function definition that is not a list and therefore
947cannot be made with @code{defun}. @xref{Classifying Lists}, for an 956cannot be made with @code{defun}. For example, you can use @code{fset}
948example of this usage. 957to 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
951In constructs for defining or altering functions. If @code{defun} 962In 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
1005See also the related function @code{defalias}, in @ref{Defining
1006Functions}.
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
1013proper results. The only way to avoid this problem is to make sure the 1027proper results. The only way to avoid this problem is to make sure the
1014file is loaded before moving aside the old definition of @code{foo}. 1028file is loaded before moving aside the old definition of @code{foo}.
1015 1029
1016See also the function @code{indirect-function} in @ref{Function
1017Indirection}.
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
1049body uses the arguments, as you do for macros. (@xref{Argument 1060body uses the arguments, as you do for macros. (@xref{Argument
1050Evaluation}.) 1061Evaluation}.)
1051 1062
1052Inline functions can be used and open coded later on in the same file, 1063Inline functions can be used and open-coded later on in the same file,
1053following the definition, just like macros. 1064following the definition, just like macros.
1054 1065
1055Emacs versions prior to 19 did not have inline functions. 1066Emacs versions prior to 19 did not have inline functions.