symbol-function
symbol-function symbol → contents
(setf (symbol-function symbol) new-contents)
The symbol need not be fbound for the SETF form. --sjl 16 Mar 92 \param{symbol}---an \term{fbound} \term{symbol}.symbol—a symbol.
contents— If the symbol is globally defined as a macro or a special operator, Removed per Barrett. -kmp 14-Feb-92 and if the \param{symbol} is \term{fbound},an object of implementation-dependent nature and identity is returned. If the symbol is not globally defined as either a macro or a special operator, and if the symbol is fbound, a function object is returned.
new-contents—a function. This shouldn't be needed, actually. \issue{FUNCTION-TYPE:X3J13-MARCH-88} The consequences of attempting to make the global \term{function} definition of a \term{symbol} be a \term{symbol}, a \term{list}, or the value returned by \funref{symbol-function} on the name of a \term{macro} or a \term{special form} are unspecified. \endissue{FUNCTION-TYPE:X3J13-MARCH-88}
7.1.1 14Accesses the symbol's function cell.
Some examples involving FBOUNDP simplified/corrected per Moore #2 (first public review) -kmp 12-May-93
(symbol-function 'car) → #<FUNCTION CAR> (symbol-function 'twice) is an error ;because TWICE isn't defined. (defun twice (n) (* n 2)) → TWICE (symbol-function 'twice) → #<FUNCTION TWICE> (list (twice 3) (funcall (function twice) 3) (funcall (symbol-function 'twice) 3)) → (6 6 6) (flet ((twice (x) (list x x))) (list (twice 3) (funcall (function twice) 3) (funcall (symbol-function 'twice) 3))) → ((3 3) (3 3) 6) (setf (symbol-function 'twice) #'(lambda (x) (list x x))) → #<FUNCTION anonymous> (list (twice 3) (funcall (function twice) 3) (funcall (symbol-function 'twice) 3)) → ((3 3) (3 3) (3 3)) (fboundp 'defun) → true (symbol-function 'defun) → implementation-dependent (functionp (symbol-function 'defun)) → implementation-dependent (defun symbol-function-or-nil (symbol) (if (and (fboundp symbol) (not (macro-function symbol)) (not (special-operator-p symbol))) (symbol-function symbol) nil)) → SYMBOL-FUNCTION-OR-NIL (symbol-function-or-nil 'car) → #<FUNCTION CAR> (symbol-function-or-nil 'defun) → NIL
None.
Should signal an error of type type-error if symbol is not a symbol.
Should signal undefined-function if symbol is not fbound and an attempt is made to read its definition. (No such error is signaled on an attempt to write its definition.)
fboundp, fmakunbound, macro-function, special-operator-p
symbol-function cannot access the value of a lexical function name produced by flet or labels; it can access only the global function value.
!!! Sandra thinks this should be in the Description. I'm not so sure. -kmp 13-Dec-91setf may be used with symbol-function to replace a global function definition when the symbol's function definition does not represent a special operator.
(symbol-function symbol) ≡ (fdefinition symbol)However,
fdefinition accepts arguments other than just symbols.