The procedures in this section may be used to construct and inspect classes.
Creates and returns a new class object.
Name is used for debugging: it is a symbol that appears in the
printed representation of the class and has no role in the semantics of
the class. Alternatively, name may be #f to indicate that
the class is anonymous.
Direct-superclasses must be a list of class objects. The new
class inherits both methods and slots from the classes in this list.
Specifying the empty list for direct-superclasses is equivalent to
specifying (list <instance>).
Direct-slots describes additional slots that instances of this class will have. It is a list, each element of which must have one of the following forms:
name (name . plist)
where name is a symbol, and plist is a property list. The first of these two forms is equivalent to the second with an empty plist.
Each of the elements of direct-slots defines one slot named name. Plist is used to describe additional properties of that slot. The following properties are recognized:
initial-valueThis property specifies the default initial value for the slot, i.e.
the value stored in the slot when an instance is created and no value is
explicitly specified by the instance constructor. If neither the
initial-value nor the initializer property is specified,
the slot has no default initial value.
initializerThis property specifies a procedure of no arguments that is called by an
instance constructor whenever an instance containing this slot is
created. The value returned by the initializer procedure is the
initial value of the slot.
accessorThis property specifies a generic procedure; make-class will add
an accessor method for this slot to the procedure. See Slots.
modifierThis property specifies a generic procedure; make-class will add
a modifier method for this slot to the procedure. See Slots.
initpredThis property specifies a generic procedure; make-class will add
an “initialized?” predicate method for this slot to the procedure.
See Slots.
Slot properties are combined in slightly complicated ways.
initial-value and
initializer for a slot in a given call to make-class; at
most one of these properties may be given.
initial-value and
initializer shadow one another. In other words, regardless of
the inherited slot properties, the resulting slot has at most one of
these two properties.
Examples of make-class:
(define <cell> (make-class '<cell> '() '()))
(define-generic cell-name (cell)) (define-generic cell-width (cell)) (define-generic cell-height (cell)) (define-generic cell-components (cell)) (define-generic set-cell-components! (cell components))
(define <contact>
(make-class '<contact>
(list <cell>)
`((name accessor ,cell-name))))
(define <compound-cell>
(make-class '<compound-cell>
(list <cell>)
`((width accessor ,cell-width)
(height accessor ,cell-height)
(components accessor ,cell-components
modifier ,set-cell-components!
initial-value ()))))
Define name to be a class. In its basic form, define-class
might have been defined by
(define-syntax define-class
(syntax-rules ()
((define-class name (class ...) slot ...)
(define name
(make-class (quote name)
(list class ...)
(quote (slot ...)))))))
Note that slot properties are handled specially by define-class.
If a direct-slot specifies a slot properties property list, the
keys of the property list (i.e. the even-numbered elements) are not
evaluated, while the datums