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

Redefining classes in PCL.



I use PCL with Lucid Common Lisp 3.0.
I have been trying to add slots into already defined PCL classes
and hoping that the dynamic inheritance would cause the slots
to be updated into instances created before redefining the
class. This does not seem to happen without visiting the
debugger first. Here are three examples to clarify the behaviour
of functions slot-exists-p and slot-boundp in these situations.

----------------------------------------------------------------------
;;; EXAMPLE 1:
;;; I try to ask the value of slot of the old instance after
;;; adding a slot into a class:


> (pcl:defclass hau () ())
NIL
> (setf *hau-1* (pcl:make-instance 'hau))
#<HAU 71050043>
> (pcl:defclass hau () ((new-slot :initarg :new-slot :initform 'new-slot)))
NIL

> (pcl:slot-value *hau-1* 'new-slot)
>>Error: When attempting to read the slot's value (slot-value),
         the slot NEW-SLOT is missing from the object #<HAU 71050043>.

PCL:SLOT-MISSING:
   Required arg 0 (CLASS): #<Standard-Class HAU 70424443>
   Required arg 1 (INSTANCE): #<HAU 71050043>
   Required arg 2 (SLOT-NAME): NEW-SLOT
   Required arg 3 (OPERATION): PCL:SLOT-VALUE
   Optional arg 4 (NEW-VALUE): NIL
:A  0: Abort to Lisp Top Level

-> 0
Abort to Lisp Top Level
Back to Lisp Top Level

> (pcl:slot-value *hau-1* 'new-slot)
NEW-SLOT

----------------------------------------------------------------------
;;; EXAMPLE 2:
;;; I add another slot in the class and look, if that slot
;;; exists in the old instance and then if it is bound in it.

> (pcl:defclass hau () ((new-slot :initarg :new-slot :initform 'new-slot)
			(other-new-slot :initarg :other-new-slot :initform 'other-new)))
NIL
> (pcl:slot-exists-p *hau-1* 'other-new-slot)
T
> (pcl:slot-boundp *hau-1* 'other-new-slot)
>>Error: When attempting to test to see if slot is bound (slot-boundp),
         the slot OTHER-NEW-SLOT is missing from the object #<HAU 71050043>.

PCL:SLOT-MISSING:
   Required arg 0 (CLASS): #<Standard-Class HAU 70424443>
   Required arg 1 (INSTANCE): #<HAU 71050043>
   Required arg 2 (SLOT-NAME): OTHER-NEW-SLOT
   Required arg 3 (OPERATION): PCL:SLOT-BOUNDP
   Optional arg 4 (NEW-VALUE): NIL
:A  0: Abort to Lisp Top Level

-> 0
Abort to Lisp Top Level
Back to Lisp Top Level

> (pcl:slot-boundp *hau-1* 'other-new-slot)
T

----------------------------------------------------------------------
;;; EXAMPLE 3:
;;; I manage to update the instance [after adding again a
;;; new slot into the class] by printing it.

> (pcl:defclass hau () ((new-slot :initarg :new-slot :initform 'new-slot)
			(other-new-slot :initarg :other-new-slot :initform 'other-new)
			(third-new :initarg :third-new :initform 'third-new)))
NIL
> *hau-1*
#<HAU 71050043>
> (pcl:slot-value *hau-1* 'third-new)
THIRD-NEW
> 

----------------------------------------------------------------------
It seems, that my old instance needs one print after redefining the class
to be updated. Is there any other way to get this done ? CLOS says, that
the updating of each instance happens at `some time' before any slot of
that instance is accessed. When is that ?

-- Pekka Jussila, Nokia Research Center.