Common Lisp is assumed.
DEFUN and friends
DEFUN creates a global function binding, which can retrieved via symbols.
(defun foo () 'foo)
Above we have a function FOO.
Let's call it:
(funcall (function foo)) ; no lexical bound function available, so it uses
; the symbol's binding
or
(funcall (symbol-function 'foo))
or
(funcall 'foo)
or
(foo)
All above access the same function.
Note: above shows that (foo)
and (funcall 'foo)
calls the same function. There is an exception: a file compiler may assume that a function FOO
does not change. This allows a Lisp compiler to inline code or to compile to faster function calling code. Calling the function via the symbol as in (funcall 'foo)
always results in a call to the current and latest binding - thus a lookup via the symbol is always needed.
FLET and LABELS
FLET and LABELS create lexically scoped function bindings. FUNCTION
can reference such a binding. Note that these bindings can't be accessed via symbols at runtime. There are only two ways:
Since both are using static lexical references, there is no lookup at runtime via symbols or similar. That means, symbols are not involved at runtime with lexical functions - they are only visible in the source code.
(flet ((foo () 'bar)) ; <- local lexical scope, function binding
(foo) ; calls the lexical bound function foo
or
(funcall (function foo)) ; calls the lexical bound function foo
but
(funcall (symbol-function 'foo)) ; calls the symbol's binding,
; not the lexical binding
and
(funcall 'foo) ; calls the symbol's binding
; not the lexical binding
)