[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
An instance has zero or more named slots; the name of a slot is a symbol. The slots of an instance are determined by its class.
Each slot can hold one value. When a slot does not have a value, the
slot is said to be uninitialized. The default initial value for a
slot is defined by the initial-value
and initializer
slot
properties.
A slot is said to be accessible in an instance of a class if the
slot is defined by the class of the instance or is inherited from a
superclass of that class. At most one slot of a given name can be
accessible in an instance. Slots are accessed by means of slot-access
methods (usually generated by make-class
).
3.1 Slot Descriptors 3.2 Slot Access Methods 3.3 Slot Access Constructors 3.4 Slot Access Procedures
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Slots are represented by slot descriptors, which are data structures providing information about the slots, such as their name. Slot descriptors are stored inside of classes, and may be retrieved from there and subsequently inspected.
#f
,
returns #f
, otherwise signals an error of type
condition-type:no-such-slot
.
#t
if object is a slot descriptor, otherwise
returns #f
.
class-slots
or class-slot
, then
this class is the argument passed to that procedure.
#t
if slot has an initial value, and #f
otherwise. The initial value is specified by the initial-value
slot property when a class is made.
initial-value
slot property when a class is made.
initializer
slot property when a class is made. This is a
procedure of no arguments that is called to produce an initial value for
slot. The result may also be #f
meaning that the slot has
no initializer.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The procedure make-class
provides slot properties that generate
methods to read and write slots. If an accessor is requested, a
method is automatically generated for reading the value of the slot. If
a modifier is requested, a method is automatically generated for
storing a value into the slot. When an accessor or modifier is
specified for a slot, the generic procedure to which the generated
method belongs is directly specified. The procedure specified for the
accessor takes one argument, the instance. The procedure specified for
the modifier takes two arguments, the instance and the new value, in
that order.
All of the procedures described here signal an error of type
condition-type:no-such-slot
if the given class or object does not
have a slot of the given name.
Slot-access methods can be generated by the procedures
slot-accessor-method
, slot-modifier-method
, and
slot-initpred-method
. These methods may be added to a generic
procedure by passing them as arguments to add-method
. The
methods generated by these procedures are equivalent to those generated
by the slot properties in make-class
.
condition-type:uninitialized-slot
is signalled.
(define-generic get-bar (object)) (add-method get-bar (slot-accessor-method <foo> 'bar)) |
(define-generic set-bar! (object bar)) (add-method set-bar! (slot-modifier-method <foo> 'bar)) |
#t
if the slot
specified by name is initialized in the instance; otherwise it
returns #f
.
(define-generic has-bar? (object)) (add-method has-bar? (slot-initpred-method <foo> 'bar)) |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
For convenience, and for consistency with the record-accessor procedures
record-accessor
and record-modifier
, each of the above
method-generating procedures has a corresponding accessor-generator.
Each of these procedures creates a generic procedure, adds an
appropriate method to it by calling the corresponding method-generating
procedure, and returns the generic procedure. Thus, for example, the
following are equivalent:
(slot-accessor <foo> 'bar) (let ((g (make-generic-procedure 1))) (add-method g (slot-accessor-method <foo> 'bar)) g) |
condition-type:uninitialized-slot
is signalled.
#t
if the
slot name in that instance is initialized, otherwise it returns
#f
.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Finally, there is another set of three procedures, which access the contents of a slot directly, given an instance and a slot name. These procedures are very slow by comparison with the above.
However, note the following. You can use these procedures in the body
of a define-method
special form in an efficient way. If the
define-method
specifies the correct number of arguments, the body
of the form contains a call to one of these procedures and nothing else,
and the specified slot name is quoted, the form is rewritten during
macro-expansion time as a call to the corresponding method-generating
procedure. For example, the following are equivalent:
(define-method p ((v <foo>)) (slot-value v 'bar)) (add-method p (slot-accessor-method <foo> 'bar)) |
condition-type:uninitialized-slot
is signalled.
#t
if the slot name in instance is
initialized, otherwise returns #f
.
[ << ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |