j831526 wrote:
lisp1 vs. lisp2???
- lisp-1 (e.g. Scheme) means that a symbol can be only one of both: a function or a variable
- lisp-2 (e.g. Common Lisp) means that a symbol can be both at the same time: a function and a variable
Don't worry too much about this yet. David Touretzky explains in later chapters of the book why a in Common Lisp a symbol can be both, a function as well as a variable, and how to deal with special cases.
j831526 wrote:
Since field-func should be a local variable in look-up, shouldn't it be available to the lambda function?
In your code the symbol
find-func is used by the
look-up function as a parameter
variable, and in the body of
look-up you want the value of the
find-func variable to be called as a
function. In Common Lisp, to call the
variable value of a symbol as a
function you need
FUNCALL or
APPLY.
The "undefined function FIELD-FUNC" error happens because Common Lisp doesn't understand that it's the
variable value of
find-func that you want to be called, so instead it looks for a
function named
find-func that it can't find because there was no
find-func function defined with
DEFUN before.
As a rule of thumb:
- In a lisp-2 (Common Lisp) function call, if a symbol is the first element of a list, the SYMBOL-FUNCTION value of the unevaluated symbol is used, and if a symbol is at any other position in the list, the SYMBOL-VALUE (the variable value) of the evaluated symbol is used.
- In a lisp-1 (Scheme) procedure call always the value of the evaluated symbol is used, independent of the symbol's position in the list. This is possible because Scheme symbols cannot have different values at the same time.
That a Common Lisp symbol can have different values is a common source of confusion for people who first have learned Scheme, and later start learning Common Lisp.
In Common Lisp this means that:
- (field-func x) - here field-func is the first element in the list, so Common Lisp looks for a function named field-func
- (funcall field-func x) - here field-func is not the first element in the list, so FUNCALL calls the variable value of field-func as a function with the argument x
In Common Lisp the special evaluation rule for the first element is necessary because otherwise it wouldn't be possible to tell if the symbol is a function or a variable.
j831526 wrote:
Apple App store ... Clozure Common Lisp ... Not sure I made the best choice.
I have no particular experience with the Apple App store version, but I can tell that Clozure Common Lisp (CCL) in general is known to be a good and stable Common Lisp implementation.
- edgar