[Openmcl-devel] Interesting behavior with CCL and CLOS

clayton stanley cstanley at cstanley.no-ip.biz
Wed Aug 1 15:35:37 PDT 2012


During development with CLOS, I often redefine a class within an active
lisp session. As far as I know, CLOS fully supports this sort of run-time
redefinition, but I found a particular case where things aren't as I expect
them to be:

CL-USER>
(defclass cup ()
  ((filled-with :accessor filled-with :initarg :filled-with :initform
'nothing)))
#<STANDARD-CLASS CUP>
CL-USER>
(filled-with (make-instance 'cup))
NOTHING
CL-USER>
(defclass cup ()
  ((filled-with :accessor filled-with :initarg :filled-with :initform
'nothing))
  (:default-initargs :filled-with 'coffee))
#<STANDARD-CLASS CUP>
CL-USER>
(filled-with (make-instance 'cup))
COFFEE
CL-USER>
(defclass cup ()
  ((filled-with :accessor filled-with :initarg :filled-with :initform
'nothing)))
#<STANDARD-CLASS CUP>
CL-USER>
(filled-with (make-instance 'cup))
COFFEE
CL-USER>
~

This was produced using a base Clozure 1.8-r15286 core file, with Swank
2012-03-06 loaded on top for the interactive repl.

I start by defining a class, make an instance, and the initform is used.
All is well. I then redefine the class and provide a :default-initarg for
that slot. I make another instance, and that initarg is used, so all is
well again. But if I then redefine the class and remove the
:default-initarg section, when I make the last instance, the
:default-initiarg for the slot is still used. I would have expected the
initform to be used in this case, since the :default-initarg for that slot
should no longer be present.

I have run into trouble a few times with this behavior, and I've started to
favor using :initform modifications (over :default-initarg) so that
dynamic/run-time class redefinitions behave as I would expect them to
behave. I'm probably just not fully understanding the CLOS specification,
so my model of how things should behave is off. If that's the case, I would
appreciate getting an explanation of why :default-initargs seem to be
maintained across run-time class redefinitions.

Thanks,
-Clayton
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.clozure.com/pipermail/openmcl-devel/attachments/20120801/7c548696/attachment.htm>


More information about the Openmcl-devel mailing list