comparison lispref/functions.texi @ 22138:d4ac295a98b3

*** empty log message ***
author Richard M. Stallman <rms@gnu.org>
date Tue, 19 May 1998 03:45:57 +0000
parents 90da2489c498
children 467b88fab665
comparison
equal deleted inserted replaced
22137:2b0e6a1e7fb9 22138:d4ac295a98b3
52 A @dfn{primitive} is a function callable from Lisp that is written in C, 52 A @dfn{primitive} is a function callable from Lisp that is written in C,
53 such as @code{car} or @code{append}. These functions are also called 53 such as @code{car} or @code{append}. These functions are also called
54 @dfn{built-in} functions or @dfn{subrs}. (Special forms are also 54 @dfn{built-in} functions or @dfn{subrs}. (Special forms are also
55 considered primitives.) 55 considered primitives.)
56 56
57 Usually the reason we implement a function as a primitive is because it 57 Usually the reason we implement a function as a primitive is either
58 is fundamental, because it provides a low-level interface to operating 58 because it is fundamental, because it provides a low-level interface to
59 system services, or because it needs to run fast. Primitives can be 59 operating system services, or because it needs to run fast. Primitives
60 modified or added only by changing the C sources and recompiling the 60 can be modified or added only by changing the C sources and recompiling
61 editor. See @ref{Writing Emacs Primitives}. 61 the editor. See @ref{Writing Emacs Primitives}.
62 62
63 @item lambda expression 63 @item lambda expression
64 A @dfn{lambda expression} is a function written in Lisp. 64 A @dfn{lambda expression} is a function written in Lisp.
65 These are described in the following section. 65 These are described in the following section.
66 @ifinfo 66 @ifinfo
108 @item byte-code function 108 @item byte-code function
109 A @dfn{byte-code function} is a function that has been compiled by the 109 A @dfn{byte-code function} is a function that has been compiled by the
110 byte compiler. @xref{Byte-Code Type}. 110 byte compiler. @xref{Byte-Code Type}.
111 @end table 111 @end table
112 112
113 @defun functionp object
113 @tindex functionp 114 @tindex functionp
114 @defun functionp object
115 This function returns @code{t} if @var{object} is any kind of function, 115 This function returns @code{t} if @var{object} is any kind of function,
116 or a special form or macro. 116 or a special form or macro.
117 @end defun 117 @end defun
118 118
119 @defun subrp object 119 @defun subrp object
456 a given function object @emph{usually} appears in the function cell of only 456 a given function object @emph{usually} appears in the function cell of only
457 one symbol, this is just a matter of convenience. It is easy to store 457 one symbol, this is just a matter of convenience. It is easy to store
458 it in several symbols using @code{fset}; then each of the symbols is 458 it in several symbols using @code{fset}; then each of the symbols is
459 equally well a name for the same function. 459 equally well a name for the same function.
460 460
461 A symbol used as a function name may also be used as a variable; 461 A symbol used as a function name may also be used as a variable; these
462 these two uses of a symbol are independent and do not conflict. 462 two uses of a symbol are independent and do not conflict. (Some Lisp
463 (Some Lisp dialects, such as Scheme, do not distinguish between a 463 dialects, such as Scheme, do not distinguish between a symbol's value
464 symbol's value and its function definition; a symbol's value as a variable 464 and its function definition; a symbol's value as a variable is also its
465 is also its function definition.) 465 function definition.) If you have not given a symbol a function
466 definition, you cannot use it as a function; whether the symbol has a
467 value as a variable makes no difference to this.
466 468
467 @node Defining Functions 469 @node Defining Functions
468 @section Defining Functions 470 @section Defining Functions
469 @cindex defining a function 471 @cindex defining a function
470 472
579 name it calls is written in your program. This means that you choose 581 name it calls is written in your program. This means that you choose
580 which function to call, and how many arguments to give it, when you 582 which function to call, and how many arguments to give it, when you
581 write the program. Usually that's just what you want. Occasionally you 583 write the program. Usually that's just what you want. Occasionally you
582 need to compute at run time which function to call. To do that, use the 584 need to compute at run time which function to call. To do that, use the
583 function @code{funcall}. When you also need to determine at run time 585 function @code{funcall}. When you also need to determine at run time
584 how may arguments to pass, use @code{apply}. 586 how many arguments to pass, use @code{apply}.
585 587
586 @defun funcall function &rest arguments 588 @defun funcall function &rest arguments
587 @code{funcall} calls @var{function} with @var{arguments}, and returns 589 @code{funcall} calls @var{function} with @var{arguments}, and returns
588 whatever @var{function} returns. 590 whatever @var{function} returns.
589 591
844 of simple quotation to quote the anonymous function, like this: 846 of simple quotation to quote the anonymous function, like this:
845 847
846 @example 848 @example
847 @group 849 @group
848 (defun double-property (symbol prop) 850 (defun double-property (symbol prop)
849 (change-property symbol prop (function (lambda (x) (* 2 x))))) 851 (change-property symbol prop
852 (function (lambda (x) (* 2 x)))))
850 @end group 853 @end group
851 @end example 854 @end example
852 855
853 Using @code{function} instead of @code{quote} makes a difference if you 856 Using @code{function} instead of @code{quote} makes a difference if you
854 compile the function @code{double-property}. For example, if you 857 compile the function @code{double-property}. For example, if you
862 @end example 865 @end example
863 866
864 @noindent 867 @noindent
865 The Lisp compiler cannot assume this list is a function, even though it 868 The Lisp compiler cannot assume this list is a function, even though it
866 looks like one, since it does not know what @code{change-property} will 869 looks like one, since it does not know what @code{change-property} will
867 do with the list. Perhaps will check whether the @sc{car} of the third 870 do with the list. Perhaps it will check whether the @sc{car} of the third
868 element is the symbol @code{*}! Using @code{function} tells the 871 element is the symbol @code{*}! Using @code{function} tells the
869 compiler it is safe to go ahead and compile the constant function. 872 compiler it is safe to go ahead and compile the constant function.
870 873
871 We sometimes write @code{function} instead of @code{quote} when 874 We sometimes write @code{function} instead of @code{quote} when
872 quoting the name of a function, but this usage is just a sort of 875 quoting the name of a function, but this usage is just a sort of
873 comment: 876 comment:
874 877
875 @example 878 @example
876 (function @var{symbol}) @equiv{} (quote @var{symbol}) @equiv{} '@var{symbol} 879 (function @var{symbol}) @equiv{} (quote @var{symbol}) @equiv{} '@var{symbol}
880 @end example
881
882 The read syntax @code{#'} is a short-hand for using @code{function}.
883 For example,
884
885 @example
886 #'(lambda (x) (* x x))
887 @end example
888
889 @noindent
890 is equivalent to
891
892 @example
893 (function (lambda (x) (* x x)))
877 @end example 894 @end example
878 895
879 @defspec function function-object 896 @defspec function function-object
880 @cindex function quoting 897 @cindex function quoting
881 This special form returns @var{function-object} without evaluating it. 898 This special form returns @var{function-object} without evaluating it.
950 @end defun 967 @end defun
951 968
952 @defun fmakunbound symbol 969 @defun fmakunbound symbol
953 This function makes @var{symbol}'s function cell void, so that a 970 This function makes @var{symbol}'s function cell void, so that a
954 subsequent attempt to access this cell will cause a @code{void-function} 971 subsequent attempt to access this cell will cause a @code{void-function}
955 error. (See also @code{makunbound}, in @ref{Local Variables}.) 972 error. (See also @code{makunbound}, in @ref{Void Variables}.)
956 973
957 @example 974 @example
958 @group 975 @group
959 (defun foo (x) x) 976 (defun foo (x) x)
960 @result{} foo 977 @result{} foo