(define-record-type type-name constructor predicate field-spec ...)
Defines a new record type, similar to "SRFI-9: Defining Record Types." The type is constructed using make-tag, and each instance of the record is backed by a vectors, enclosed within a cell.
(import "lib/record") ;; Define a new type, <point> (define-record-type point (make-point x y) point? (x point-x set-point-x!) (y point-y set-point-y!)) ;; A simple function that formats <point>s. (define (format-point p)) (string-append "[x: " (format (point-x x)) " y: " (format (point-y y)) "]"))
>> (load "examples/point.ms") >> (define pt (make-point 111 222)) >> (format-point pt) :: "[x: 111 y: 222]" >> (set-point-x! pt "foo") >> (format-point pt) :: "[x: \"foo\" y: 222]"