Next: , Previous: , Up: Scheme reference   [Contents][Index]


4.10 Records

Hoot extends the R7RS define-record-type form with additional features such as inheritance and opaque types.

Syntax: define-record-type name [#:printer] [#:parent] [#:uid] [#:extensible? #t] [#:opaque? #f] [#:allow-duplicate-field-names? #f] constructor predicate (field field-ref [field-set]) ...

Define a new record type descriptor bound to name. Define a constructor procedure bound to constructor and a predicate procedure bound to predicate. For each field, define an accessor procedure field-ref and, optionally, a modifier procedure field-set.

The record type will inherit from the record type descriptor bound to parent, as long as parent is extensible. By default, record types are extensible. A record type may be marked as “final” by passing an extensible? flag of #f.

When opaque? is #t, instances of this record type will be compared for equality by identity only. This means that (equal? a b) only returns #t when a and b reference the same instance of the record type. In other words, they must be eq?. The default behavior is to perform deep structural equality checking by comparing record fields.

When printer is specified, that procedure will be used when printing instances of this record type rather than the default printer.

uid should be a unique identifier that will be associated with the record type when specified. Record types have no unique id by default.

When allow-duplicate-field-names? is #t, field names may appear more than once in the fields section.