On this page:
define-record-type
record-type?
record-type
record-type-name
record-type-fields
record-type-predicate-name
record-type-constructor-name
record-type-accessor-name
make-record-implementation
record-descriptor?
initialized-record-descriptor?
uninitialized-record-descriptor?
record-descriptor-type
record-descriptor-predicate
record-descriptor-constructor
record-descriptor-accessor
make-record-field-accessor
default-record-properties
default-record-equal+  hash
default-record-custom-write
7.4

2.2 Record Types

 (require rebellion/type/record) package: rebellion

A record type is a kind of data type for composite values that contain an unordered set of named fields. The definition of each record type declares how many fields it has and what their names are. Constructing an instance of a record type requires passing a keyword argument for each field to the type’s constructor. Record types are useful when a fixed number of different pieces of data together represent a single logical thing, and there isn’t an obvious order to those pieces.

Examples:
(define-record-type opcode (name argument addressing-mode))
(define add-42
  (opcode #:name 'ADD
          #:argument 42
          #:addressing-mode 'immediate))

 

> add-42

(opcode #:addressing-mode 'immediate #:argument 42 #:name 'ADD)

> (opcode-name add-42)

'ADD

syntax

(define-record-type id (field-id ...) option ...)

 
option = #:constructor-name constructor-id
  | #:predicate-name predicate-id
  | #:property-maker prop-maker-expr
 
  prop-maker-expr : 
(-> uninitialized-record-descriptor?
    (listof (cons/c struct-type-property? any/c)))
Creates a new record type named id and binds the following identifiers:

Examples:
(define-record-type color (red green blue))
(define yellow  (color #:red 0 #:green 255 #:blue 255))

 

> yellow

(color #:blue 255 #:green 255 #:red 0)

> (color? yellow)

#t

> (color-red yellow)

0

> (color-green yellow)

255

> (color-blue yellow)

255

procedure

(record-type? v)  boolean?

  v : any/c
A predicate for record types.

procedure

(record-type name 
  fields 
  [#:predicate-name predicate-name 
  #:constructor-name constructor-name 
  #:accessor-name accessor-name]) 
  record-type?
  name : symbol?
  fields : keyset?
  predicate-name : (or/c symbol? #f) = #f
  constructor-name : (or/c symbol? #f) = #f
  accessor-name : (or/c symbol? #f) = #f

procedure

(record-type-name type)  symbol?

  type : record-type?

procedure

(record-type-fields type)  keyset?

  type : record-type?

procedure

(record-type-predicate-name type)  (or/c symbol? #f)

  type : record-type?

procedure

(record-type-constructor-name type)  (or/c symbol? #f)

  type : record-type?

procedure

(record-type-accessor-name type)  (or/c symbol? #f)

  type : record-type?

procedure

(make-record-implementation type 
  [#:inspector inspector 
  #:property-maker prop-maker]) 
  initialized-record-descriptor?
  type : record-type?
  inspector : inspector? = (current-inspector)
  prop-maker : 
(-> uninitialized-record-descriptor?
    (listof (cons/c struct-type-property? any/c)))
   = default-record-properties

procedure

(record-descriptor? v)  boolean?

  v : any/c

procedure

(initialized-record-descriptor? v)  boolean?

  v : any/c

procedure

(uninitialized-record-descriptor? v)  boolean?

  v : any/c

procedure

(record-descriptor-type descriptor)  record-type?

  descriptor : record-descriptor?

procedure

(record-descriptor-predicate descriptor)  (-> any/c boolean?)

  descriptor : record-descriptor?

procedure

(record-descriptor-constructor descriptor)  procedure?

  descriptor : record-descriptor?

procedure

(record-descriptor-accessor descriptor)

  (-> (record-descriptor-predicate descriptor) natural? any/c)
  descriptor : record-descriptor?

procedure

(make-record-field-accessor descriptor 
  field) 
  (-> (record-descriptor-predicate descriptor) any/c)
  descriptor : record-descriptor?
  field : natural?

procedure

(default-record-properties descriptor)

  (listof (cons/c struct-type-property? any/c))
  descriptor : record-descriptor?

procedure

(default-record-equal+hash descriptor)  equal+hash/c

  descriptor : record-descriptor?

procedure

(default-record-custom-write descriptor)

  custom-write-function/c
  descriptor : record-descriptor?