The question is already a little wrong.
We are talking about different things in Common Lisp:
- symbol : data structure in Lisp. A symbol is a data object with a name, value, function, package, and possibly more.
In Common Lisp, a character can have both a value and a function (or macro).
- a variable is an identifier for a value in Lisp code
There are top-level variables defined by DEFVAR and DEFPARAMETER. There are also local variables defined by LAMBDA, DEFUN, LET, LET * and others.
(defun foo (i-am-a-variable) ...) (defparameter *i-am-a-global-variable* ...)
- A named function is the identifier of a function in Lisp code. Named functions are entered at the top level using DEFUN, DEFGENERIC and DEFMETHOD. There are also local named functions defined by FLET and LABELS.
Example:
(defun i-am-a-function (foo) ...) (flet ((i-am-a-function (foo) ...)) ...)
For further functions of the complication function, the names and names of variables are symbols in the source code.
Example:
(type-of (second '(defun foo () nil))) --> SYMBOL
Look at the functions and variables:
(defun foo () (let ((some-name 100)) (flet ((some-name (bar) (+ bar 200))) (+ some-name (some-name some-name)))))
The above code uses a variable and function with the same character in the source code. Since functions and variables have their own namespace, no conflict arises.
(+ some-name (some-name some-name))
Above, that means we add the variable to the result of the function call for the variable.
This has a practical effect that you can do something like this:
(defun parent (person) ...) (defun do-something (parent) (parent parent))
You need not fear that your local variable names will obscure the global (or local) function. They just reside in different namespaces.
There is only one namespace in the schema, and we must write
(define (foo lst) (list 'a lst 'n))
where in Common Lisp we can write:
(defun foo (list) (list 'a list 'n))
In Common Lisp, there is no need to write lst instead of list - because there is no collision between the local variable list and the global function list .
Access to another namespace
To get the function object stored in a variable, you can use FUNCTION .
(let ((my-function (function numberp))) (funcall my-function 10))
(function foo) can be written shorter as #'foo .
FUNCALL calls the function object.
OTOH, if you want to save a function object from a variable in the function namespace, there is only one way:
(setf (symbol-function 'foo) my-function)
It is also necessary that the object is really a function, and not something else (a number, a string, ...). Otherwise, you will see an error message.
A side effect of this is that Common Lisp should never check if FOO is really a function in (foo bar) . There is no way that it can be different from a function or undefined.