Previous: , Up: srfi records   [Index]

2.6.4 Specification

The syntax of a record–type definition is:

<command or definition>
  -> <record type definition>           ; addition to 8.1.6 in R5RS

<record type definition>
  -> (define-record-type <type name>
       (<constructor name> <field tag> ...)
       <predicate name>
       <field spec> ...)

<field spec> -> (<field tag> <accessor name>)
             -> (<field tag> <accessor name> <modifier name>)

<field tag> -> <identifier>
<... name>  -> <identifier>

define-record-type is generative: each use creates a new record type that is distinct from all existing types, including other record types and Scheme’s predefined types. Record–type definitions may only occur at top–level (there are two possible semantics for “internal” record–type definitions, generative and nongenerative, and no consensus as to which is better).

An instance of define-record-type is equivalent to the following definitions:

Records are disjoint from the types listed in Section 4.2 of R5RS.

set!–ing the value of any of these identifiers has no effect on the behavior of any of their original values.

The following:

(define-record-type :pare
  (kons x y)
  (x kar set-kar!)
  (y kdr))

defines kons to be a constructor, kar and kdr to be accessors, set-kar! to be a modifier, and pare? to be a predicate for :pares.


(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

Previous: , Up: srfi records   [Index]