Records

R6RS records add inheritance ((parent ...)), sealed/opaque records, and a procedural layer. Guile, Chez, and Racket also offer define-record-type extensions (printers, inheritance).

;; R7RS / SRFI-9 records
(define-record-type point
  (make-point x y)              ; constructor
  point?                        ; predicate
  (x point-x set-point-x!)      ; field, accessor, modifier
  (y point-y))                  ; field, accessor (read-only)

(define p (make-point 3 4))
(point-x p)                     ; 3
(set-point-x! p 10)
(point? p)                      ; #t
(point? 42)                     ; #f

(define (distance a b)
  (sqrt (+ (square (- (point-x a) (point-x b)))
           (square (- (point-y a) (point-y b))))))
(distance (make-point 0 0) (make-point 3 4))   ; 5

;; Records with validation through a wrapper constructor
(define-record-type <account>
  (%make-account owner balance)
  account?
  (owner account-owner)
  (balance account-balance set-account-balance!))
(define (make-account owner balance)
  (unless (and (string? owner) (>= balance 0)) (error "invalid account" owner balance))
  (%make-account owner balance))