Next: Slot Access Optimization, Previous: Primary Method Errors, Up: CLOS [Contents][Index]
Declared slot types are used when
slot-value
in methods, or
(setf slot-value)
in methods, or
make-instance
, when slots are
initialized from initforms. This currently depends on PCL being
able to use its internal make-instance
optimization, which it
usually can.
Example:
(defclass foo () ((a :type fixnum))) (defmethod bar ((object foo) value) (with-slots (a) object (setf a value))) (defmethod baz ((object foo)) (< (slot-value object 'a) 10))
In method bar
, and with a suitable safety setting, a type error
will occur if value
is not a fixnum
. In method
baz
, a fixnum
comparison can be used by the compiler.
Slot type checking can be turned off by setting this variable to
nil
, which can be useful for compiling code containing incorrect
slot type declarations.