Sam Steingold <[EMAIL PROTECTED]> writes:

>> * Raymond Toy <[EMAIL PROTECTED]> [2004-10-22 09:32:51 -0400]:
>>
>>>>>>> "Sam" == Sam Steingold <[EMAIL PROTECTED]> writes:
>>
>>     Sam> the objects for which the load forms cannot be created are just 
>> regular
>>     Sam> structure objects, like
>>
>>     Sam> (defstruct foo bar)
>>     Sam> (defparameter *foo* #S(foo :bar 10))
>>
>> Don't you need to define a make-load-form for this?
>
> maybe, but GCL, CLISP and LW work without a MAKE-LOAD-FORM method.

That's irrelevant, and probably (in each of those implementations)
non-conforming.  (See CLHS 3.2.4.4, paragraph "structure,
standard-object", and the definitions of the behaviour of the
MAKE-LOAD-FORM method on STRUCTURE-OBJECT in the page for
MAKE-LOAD-FORM).

> when I add this:
>
> #+cmu
> (defmethod make-load-form ((self structure-object) &optional environment)
>   (make-load-form-saving-slots self :environment environment))
>
> I get a zillion errors:

Quite right too.  Why do you think that this make-load-form method is
applicable to every single STRUCTURE-OBJECT in the system?  Package
objects (probably implemented as structures) are certainly not
externaliseable like this.

Try

--- foo.lisp ---
(defstruct foo bar)
(defmethod make-load-form ((self foo) &optional environment)
  (make-load-form-saving-slots self :environment environment))
--- foo.lisp ---

--- bar.lisp ---
(defparameter *foo* #s(foo :bar 10))
--- bar.lisp ---

--- REPL session ---
(load (compile-file "foo.lisp"))
(compile-file "bar.lisp")
(load *)
--- REPL session

(You need the two separate files because the compiler needs to know
the method on MAKE-LOAD-FORM before it can compile the literal
reference to the FOO structure.)

In general, when the file compiler sees a literal object as data, it
needs to know how to arrange that a "similar" object be reconstructed
at fasl load time.  For various built in classes, the behaviour is
defined and uncustomizeable: CLHS 3.2.4.2.2 has the details.  For
structure-objects and standard-objects, however, it is specified that
MAKE-LOAD-FORM is called, and MAKE-LOAD-FORM must return a form that
builds a "similar" (for an individual application programmer's
definition of "similar") object; since the Lisp system cannot know in
general what similarity relationships should hold between arbitrary
structures, the mandated default of signalling an error is probably a
sensible one.

Cheers,

Christophe

Reply via email to