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

Issue: LOAD-OBJECTS (Version 1)

Defstruct needs a :LOAD-FUNCTION (or whatever) option, and a rule for how
you get the simple slot-recreation function.  I still think that it's going to
be awkward and confusing for this to default differently from :PRINT-FUNCTION
or :CONSTRUCTOR (both of which give you a default function if not specified),
but I guess nobody else does, so I won't press it...

I take it the form returned by MAKE-LOAD-FORM is walked again by the
file compiler, and it's the user's responsibility to avoid circularity
(as in (defmethod make-load-form ((x y)) `',x) or equivalent multi-level
examples).  If so, this should be stated.

It would be useful to make the simple slot-recreation function available as
part of the language.  Something like
   (slot-reconstruct-form x) -> (make-instance '<class-name> :a <a> ...)
so they can do
   (defmethod make-load-form ((x my-class)) (slot-reconstruct-form x))
The reason for this, aside from making things simpler for users doing
simple things, is that the obvious MAKE-LOAD-FORM doesn't work well with
inheritance.  That is, if a user writes
  (defclass person ()
     ((name :reader person-name)
      (age :reader person-age)))
  (defmethod make-load-form ((jrandom person))
     `(make-instance ',(class-name (class-of jrandom))
	            :name ',(person-name jrandom)
                    :age ',(person-age jrandom)))
as recommended by the examples, and then does
   (defclass astronaut (person)
      ((helmet-size :initarg 17)))
without specifing a make-load-form, then he's going to quietly lose dumping
astronauts in a very difficult to detect way.