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:<div>
<br></div><div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse:collapse"><div>CL-USER></div><div>(defclass cup ()</div><div> ((filled-with :accessor filled-with :initarg :filled-with :initform 'nothing)))</div>
<div>#<STANDARD-CLASS CUP></div><div>CL-USER> </div><div>(filled-with (make-instance 'cup))</div><div>NOTHING</div><div>CL-USER> </div><div>(defclass cup ()</div><div> ((filled-with :accessor filled-with :initarg :filled-with :initform 'nothing))</div>
<div> (:default-initargs :filled-with 'coffee))</div><div>#<STANDARD-CLASS CUP></div><div>CL-USER> </div><div>(filled-with (make-instance 'cup))</div><div>COFFEE</div><div>CL-USER> </div><div>(defclass cup ()</div>
<div> ((filled-with :accessor filled-with :initarg :filled-with :initform 'nothing)))</div><div>#<STANDARD-CLASS CUP></div><div>CL-USER> </div><div>(filled-with (make-instance 'cup))</div><div>COFFEE</div>
<div>CL-USER> </div><div>~ </div><div><br></div><div>This was produced using a base Clozure 1.8-r15286 core file, with Swank 2012-03-06 loaded on top for the interactive repl.</div><div><br></div><div>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.</div>
<div><br></div><div>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. </div>
<div><br></div><div>Thanks,</div><div>-Clayton</div></span></font></div>