[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: EVAL-WHEN (really symbol-function)
From: Guy Steele <hplabs!gls@THINK-AQUINAS.ARPA>
Date: 4 Apr 1986 09:35-EST
From: NGALL@G.BBN.COM
Date: Thu 3 Apr 86 22:52:12-EST
From: "Rodney A. Brooks" <BROOKS%OZ.AI.MIT.EDU@XX.LCS.MIT.EDU>
There is no requirement in CLtL that it be legal for a symbol function
cell to contain a lambda expression. In some implementations this
will cause an error when such a symbol is used in the function
position of an eval-ed expression. These implementations place a closure
in symbol function cells for interpreted functions, which all point
to the same compiled code sequence which takes a literal from the
closure (the literal is the lambda expression) and does the right
call into the middle of the interpreter.
I agree.
This should definitely be pointed out on page 90. Also, exactly what
objects may be the value in a setf of (symbol-function <<symbol>>)
should be clarified.
Apparently, this too is true (considering that all of us do not seem to agree
on this).
I would contend that any Lisp object may be the value in a setf of
(symbol-function <symbol>), and that a subsequent invocation of
(symbol-function <symbol>) should retrieve exactly that object (or one
EQL to it). However, this does not prevent implementations from
wrapping that object in a closure internally on storing and unwrapping
it again on fetching.
--Guy
I have to disagree with you, Guy, for the following reason. The following
piece of code is perfectly legal Common Lisp:
(defun evaluate-fun (func &rest args)
(if (or (null (symbol-function func))
(macro-function func)
(special-form-p func))
(error "Not a function.")
(apply (symbol-function func) args))) ; I know that the symbol-function
; is redundant here -- that isn't
; the point
(evaluate-fun 'cons 'a 'b) ; should return (A . B)
Here is what CLtL says (p. 90):
"symbol-function returns the current global function definition named by
symbol. An error is signalled if the symbol has no function definition;
see fboundp. Note that the definition may be an object representing a
special form or macro. In the latter case, it is an error to attempt to
invoke the object as a function."
Note that the only valid object which may be returned is something of type
function (if the symbol has a global function definition). This is obvious
from the last sentence in the paragraph above. Since you claim
any object can be stored and that the retrieved value must be EQL, then any
object can be retrieved. This is totally contradictory to the quoted
paragraph above. It very explicitly states in which cases it is an error to
invoke the object as a function, and the case you are establishing is not
covered.
As far as allowing a lambda as the function cell, CLtL states that an
implementation is at liberty to always compile its code. If the lambda must
be left in its original state, then the implementation has to compile every
time a function is called, rather than when one is defined!
John Diamant
Systems Software Operation UUCP: {ihnp4!hpfcla,hplabs}!hpfclp!diamant
Hewlett Packard Co. ARPA/CSNET: diamant%hpfclp@hplabs
Fort Collins, CO