[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

EVAL-WHEN



Mr. Fry has begun our bimonthly discussion of EVAL-WHEN (on April 1,
no less).  I think, however, that the case of (EVAL-WHEN (LOAD) 
(DEFUN...)) is straightforward.  When the book says that "the compiler 
should arrange to evaluate the forms in the body when the compiled file 
... is loaded", it means that the DEFUN should be evaluated to produce 
its effect of stashing a function in the symbol's definition.  I don't 
think anyone meant to imply that the body of the DEFUN had to be 
processed in any particular fashion (e.g., macroexpanding it at load
time).  But I'll acknowledge that it's not precisely clear.

If you do want the DEFUN to be processed as if it was entered at 
top-level, you might do the following, which will produce an interpreted 
definition:

(EVAL-WHEN (LOAD)
(EVAL '(DEFUN ...))
)

A related question is what to do with other sorts of top-level forms, 
not DEFUNs or DEFMACROS.  Some LISPs have a (perhaps secret) switch 
which determines whether the compiler dumps anonymous compiled functions 
or dumps the lists and interprets them at load time.  There may be 
demantic differences resulting from the choice.

A couple of other questions have been asked before and never really 
answered.  Are EVAL-WHENs allowed down in the guts of a function or 
macro and what do they mean there?  Also, would it clarify things if we 
acknowledged the fourth EVAL-WHEN situation, that of the compiler 
digesting a definition without actually evaluating it?  This occurs, for 
example, when the compiler sees a DEFMACRO.  It doesn't evaluate it per 
se, but it does digest it enough to be able to expand future macro calls.
It's not sufficient to say that DEFMACRO is a special case and the 
compiler always looks at it, because the compiler doesn't look if it's 
wrapped in an (EVAL-WHEN (EVAL) ...).  This implies that there is some 
secret situation that has been left out of the list.

- Paul
------