Classes and instances
:allocation option when you define the slot.
The two :allocation options are :instance and :class. The :instance option is the default; this option means that each instance of a class has local storage for the slot that can be associated with its own value. The :class option specifies that the class stores the value of the slot. A slot of this kind is called a shared slot or a class slot. The following code defines picky-fourth-grader, associating it with a class slot for subjects-studied:
? (defclass picky-fourth-grader
(fourth-grader)
((subjects-studied
:initarg subjects-studied
:initform '(English math woodworking)
:allocation :class)))
#<STANDARD-CLASS PICKY-FOURTH-GRADER>
Since all instances of picky-fourth-grader access the same subjects-studied slot, you can setf the class slot value through any instance:
? (setf zane (make-instance 'picky-fourth-grader))
#<PICKY-FOURTH-GRADER #x40CDC9>
? (setf justus (make-instance 'picky-fourth-grader))
#<PICKY-FOURTH-GRADER #x40EFC8>
? (setf (slot-value zane 'subjects-studied)
'(English math woodworking phenomenology))
(ENGLISH MATH WOODWORKING PHENOMENOLOGY)
? (slot-value justus 'subjects-studied)
(ENGLISH MATH WOODWORKING PHENOMENOLOGY)
Generated with Harlequin WebMaker