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

Another Common Lisp unclarity

    While we are discussing issues needing to be resolved, I will drag
out yet another problem which has been discussed in the past.  It
would be nice if someone would keep track of these things starting
*now* so that we don't have to iterate N times.

    The problem is with the notion of "top level forms" and things
containing a EVAL-WHEN (COMPILE), possibly implicit.  Examples of
forms with implicit compiler evaluation are PROCLAIM, DEFMACRO and
DEFCONSTANT.  Other possibles are package manipulation.

    The question is whether the compile-time action is done when the
form appears in a context where it is not obvious that the form will
ever be evaluated at run time.  What happens if the compiler finds this?
  (if (oddp (get-universal-time))
      (defmacro foo ...)
      (defmacro foo ...))

    My answer is that the compiler always does the evaluation, no
matter where the forms appears.  The manual seems to support this
interpretation.  See the definition of EVAL-WHEN on 69 and DEFMACRO on
146.  If this is the correct interpretation, then the manual should
say so, possibly illustrating with an example, since this can result
in non-obvious problems, especially for naive users who foolishly
believe that programs do the same thing when compiled as when

    There is some question about what to do with the package
functions.  Probably they only want to be evaluated when the function
appears "really at top level".  We wouldn't want compilation of this
function to die with an unbound-symbol error:
    (defun my-export (syms) (export syms "MY-PACKAGE"))
This contradicts the manual, since on page 182 it says that these
functions are implicitly wrapped in an EVAL-WHEN (COMPILE LOAD EVAL).