[Openmcl-devel] Defstruct inside eval-when strangeness and a build failure

Gary Byers gb at clozure.com
Wed Dec 30 02:41:19 PST 2009



On Tue, 29 Dec 2009, Gary Byers wrote:

>
>
> On Mon, 28 Dec 2009, Stas Boukarev wrote:
>
>> Compiling and loading the following results in "Undefined function FOO"
>>
>> (defun foo (&rest args)
>>  (print "HELLO!"))
>>
>> (eval-when (:compile-toplevel :load-toplevel :execute)
>>  (defstruct (test (:print-function foo))))
>>
>> (foo)
>>
>
> This behaves the same way when the DEFSTRUCT isn't enclosed in an
> EVAL-WHEN, as far as I can tell.

After actually looking at the code, it seems that this happens when
a structure is redefined (as a structure or standard class).  Using
EVAL-WHEN as your example does is one way of causing the structure
class to be redefined (at load time after it'd been defined at compile
time), even though those definitions happen to be equivalent.

The rationale for doing FMAKUNBOUND in this case has less to do with
avoiding redefinition warnings than with un-defining (possibly obsolete)
functions.  (The consequences of redefining a DEFSTRUCT are undefined;
the consequences of calling a stale/obsolete constructor/accessor/...
are undefined and often unpleasant.)

There's at least some stronger justification than I'd thought there
was for removing (possibly) obsolete automatically-generated structure
functions, even though in many cases (EVAL-WHEN at multiple times,
re-loading a file that contains an un-changed strucure definition) the
old functions are functionally equivalent to the new.  There's even
a little bit of justification for removing a user-defined structure
print-function (that may reference obsolete slots, etc.) but not
enough justification  to actually do that removal.  (The results
of executing code compiled with an obsolete structure definition
in effect are "undefined and sometimes unpleasant", and that's no
more or less true of a print function than it is of other user-defined
code.)





More information about the Openmcl-devel mailing list