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

time of evaluation



    I think it's a bad idea to make defstruct literally
eval-when (compile load eval).  It will cause you (the implementor) no
end of grief even if it doesn't bother users much.  In Spice Lisp, our
current solution is to have two separate defstruct definition
properties, DEFSTRUCT-DEFINITION and DEFSTRUCT-DEFINITION-IN-COMPILER.
The -IN-COMPILER property is set when the defstruct is compiled, and
the normal definition is set at load time.  The compiler definition is
used preferentially for purposes of inclusion and any compiler uses.

    Compiling a defstruct puts compiler information into the
environment so that accessors and predicates are open-coded, but the
actual function definitions are not put into the environment.  One
problem with a strict eval-when compile strategy is that it causes any
accessors in the environment to be clobbered with interpreted
definitions.  We also had problems with compiling the file which
defines streams breaking the type structure such that *TERMINAL-IO*
was no longer a stream, with understandably serious consequences.

    I'm sure that there are lots of problems with this approach, both
in particular and in general, since it is similar to the defmacro
problem but more complicated due to the more complicated semantics of
defstruct.  Nonetheless, I think that an approach like this is
expedient for the same reasons that make special-casing macros
important.

  Rob