FUNCTION
Function form expects one argument, most typically a symbol. It will look up a function object associated with the symbol. The FUNCTION
form is related to quoting and has the special character #'
(sharp-quote). A symbol in LabLISP can name a variable and a function at the same time - like in Common LISP, there are separate namespaces for values and functions. A symbol in an expression is evaluated to the function if it stands first in the form, otherwise it is evaluated to the value as variable. With sharp-quoting a symbol, we force evalation to the function named by it.
Following example should make this more clear
>(setq f 3) ; we defined variable F, with value 3 3 >(defun f () 42) ; we defined function F, with no parameters, returning 42 F
Now we have symbol F which has both value and function, let's see how it evaluates
>f ; we are evaluating just symbol outside of form 3 >(+ 1 f) ; F will be evaluated to value 3 4 >(f) ; function call to F 42 >'f ; quoting F F >#'f ; (FUNCTION F) call returns the function object itself #<user-defined function F>
See also functions SYMBOL-VALUE
, SYMBOL-FUNCTION
in the Package and symbol operations section, and the applicative functions FUNCALL
and APPLY
in Management section.
See also the future section 1.3.4 for more details.