Here is my Common Lisp code:
(defun caller (f)
(format t "caller: f: ~a~%" f)
(funcall f 10))
(defun callee (x)
(format t "callee: x: ~a~%" x))
(caller #'callee)
(caller 'callee)
Here is the output I get with clisp
:
$ clisp foo.lisp
caller: f: #<FUNCTION CALLEE (X) (DECLARE (IN-DEFUN CALLEE)) (BLOCK CALLEE (FORMAT T callee: x: ~a~% X))>
callee: x: 10
caller: f: CALLEE
callee: x: 10
I want to know what is the difference between the syntax #'callee
and the syntax 'callee
.
Although with both syntaxes, I am able to pass the callee
to the caller
, the caller: f:
output seems to indicate that there is some subtle difference in both the syntaxes: #'callee
seems to refer to a function object but 'callee
seems to refer to just the function name.
Here are my questions:
- What's the difference between the
#'callee
syntax and the'callee
syntax? - How is it that
funcall
is able to invoke thecallee
in both cases successfully? - Is there any best practice or pros and cons associated with both syntaxes due to which one is preferred over another?