Node:SRFI-9, Next:, Previous:SRFI-8, Up:SRFI Support

39.8 SRFI-9 - define-record-type

This is the SRFI way for defining record types. The Guile implementation is a layer above Guile's normal record construction procedures (see Records). The nice thing about this kind of record definition method is that no new names are implicitly created, all constructor, accessor and predicates are explicitly given. This reduces the risk of variable capture.

The syntax of a record type definition is:

<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>

Usage example:

guile> (use-modules (srfi srfi-9))
guile> (define-record-type :foo (make-foo x) foo?
                           (x get-x) (y get-y set-y!))
guile> (define f (make-foo 1))
guile> f
#<:foo x: 1 y: #f>
guile> (get-x f)
guile> (set-y! f 2)
guile> (get-y f)
guile> f
#<:foo x: 1 y: 2>
guile> (foo? f)
guile> (foo? 1)