Define-Class
(define-class type-name-symbol parent-type-expression type-constructor predicate-name-symbol field-spec ...) -> #f
- type-name-symbol -- the symbol used by show when explaining the type.
- parent-type-expression -- Must be a valid, existing type that the new class will inherit from.
- constructor-formals -- a list (constructor-name field-name ...) Any fields named in field-spec's must be included in the constructor-formals. The constructor should contain the same fields as the parent type's constructor, in the same order, and before any additional fields being added for the new type.
- predicate-name-symbol will be the name bound to the predicate for determining if a value is of the record type.
- field spec -- (field-name-symbol field-accessor-name-symbol field-modifier-name-symbol)
field-modifier-name-symbol may be omitted; if it is, field-accessor-name-symbol may be omitted.
- field accessor -- a function that accepts a record value and returns the value of the specified field.
- field modifier -- a function that accepts a record and a value, and will alter the value of that record's field.
define-class extends other types defined by define-class forms, adding more fields to the parent type to create a new one.
The constructor should contain the same fields as the parent type's constructor, in the same order, and before any additional fields being added for the new type.
Example: We will base this example off the one given in define-record-type, as it uses the one created there as the parent-type-expression:
(define-class point3d <point> (make-point3d x y z) point3d? (x point-z set-point-z!))
Note that we do not define point-x and point-y field specifiers for point3d, because the ones defined for point will also work on point3d's.
See Also: <object>