[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Problem with dynamic slots
- To: commonloops.pa@Xerox.COM
- Subject: Problem with dynamic slots
- From: macgreg@vaxa.isi.edu
- Date: Thu, 26 May 88 10:51:34 PDT
- Cc: macgreg@vaxa.isi.edu
- Posted-date: Thu, 26 May 88 10:51:34 PDT
- Redistributed: commonloops.pa
In our application of PCL, we create classes with many "optional" slots,
which will contain the value NIL most of the time. To save space, we
declare these slots with :allocation :dynamic. We hit a bug when we
brought up the St. Patrick's Day version of PCL:
When we execute the following on a Symbolics, we generate an error:
(defclass foo ()
((name :allocation :dynamic)))
(setq i (make-instance 'foo))
(slot-value i 'name)
D,#TD1PsT[Begin using 006 escapes](1 0 (NIL 0) (NIL :BOLD NIL)
"CPTFONTCB")Trap: The function PCL:*SLOTD-UNSUPPLIED* is undefined.
(2 0 (NIL 0) (NIL NIL NIL) "CPTFONT")While in the function
PCL:SLOT-VALUE-USING-CLASS--CLASS-INTERNAL
The condition signalled was DBG:UNDEFINED-FUNCTION-TRAP
1PCL:SLOT-VALUE-USING-CLASS--CLASS-INTERNAL2: (P.C. = 241) (3 0 (NIL 0)
(NIL :ITALIC NIL) "CPTFONTI")(from DOG-CHOW:>pcl>SLOTS)
2 Arg 0 (PCL:CLASS): #<Standard-Class PCL:FOO 224011360>
Arg 1 (PCL:OBJECT): #<Standard-Instance 33036707>
Arg 2 (PCL:SLOT-NAME): PCL:NAME
Arg 3 (PCL:DONT-CALL-SLOT-MISSING-P): NIL
Arg 4 (PCL:DEFAULT): NIL
The top-level "fix" is to include an :initform option in our slot
declaration:
(defclass foo2 ()
((name :allocation :dynamic :initform nil)))
(setq i2 (make-instance 'foo2))
This works. However, our "fix" has the undesirable property that
reading a such a dynamic slot causes space to be allocated on the
association list, i.e., instead of saving space we are using
four-times as much.
(elt i2 3)
--> NIL
(slot-value i2 'name)
(elt i2 3)
--> (NAME NIL)
Are we correct in thinking that reading an empty dynamic slot having no
:initfunction should generate no space? We realize that dynamic slots
aren't a part of the CLOS standard. Nevertheless, we find them useful,
and hope that they will continue to appear in PCL (e.g., that they will
survive the current round of permutation-vector optimizations).