Record-type definitionsRecord-type definitions are used to introduce new data types, called record types. Like other definitions, they can appear either at the outermost level or in a body. The values of a record type are called records and are aggregations of zero or more fields, each of which holds a single location. A predicate, a constructor, and field accessors and mutators are defined for each record type.
(define-record-type
{name} {constructor} {pred} {field} ...
)
syntax
Syntax:
name and pred are identifiers.
The constructor is of the form
({constructor name} {field name} ...)
and each field is either of the form
({field name} {accessor name})
or of the form
({field name} {accessor name} {modifier name})
It is an error for the same identifier to occur more than once as a field name. It is also an error for the same identifier to occur more than once as an accessor or mutator name.
The
An instance of
For instance, the following record-type definition
(define-record-type
defines
(pare? (kons 1 2)) ==> #t
(pare? (cons 1 2)) ==> #f
(kar (kons 1 2)) ==> 1
(kdr (kons 1 2)) ==> 2
(let ((k (kons 1 2)))
(set-kar! k 3)
(kar k)) ==> 3
|