Next: , Previous: Syntax-Case Macros, Up: Scheme Syntax Extension Packages

3.7 Define-Structure

(require 'structure)

Included with the syntax-case files was structure.scm which defines a macro define-structure. Here is its documentation from Gambit-4.0:

— special form: define-structure (name field...)

Record data types similar to Pascal records and C struct types can be defined using the define-structure special form. The identifier name specifies the name of the new data type. The structure name is followed by k identifiers naming each field of the record. The define-structure expands into a set of definitions of the following procedures:

Gambit record data types have a printed representation that includes the name of the type and the name and value of each field.

For example:

          > (require 'syntax-case)
          > (require 'repl)
          > (repl:top-level macro:eval)
          > (require 'structure)
          > (define-structure (point x y color))
          > (define p (make-point 3 5 'red))
          > p
          #<point #3 x: 3 y: 5 color: red>
          > (point-x p)
          > (point-color p)
          > (point-color-set! p 'black)
          > p
          #<point #3 x: 3 y: 5 color: black>