| 1 | ; Each field clause names its accessor and, optionally, its mutator. |
| 2 | define-record-type(point, make-point(x,y), point?, x(point-x,set-point-x!), y(point-y)) |
| 3 | p := make-point(20,22) |
| 4 | set-point-x!(p,21) |
| 5 | display(point?(p)) |
| 6 | newline() |
| 7 | display(point-x(p)+point-y(p)) |
| 8 | newline() |
| 9 | |
| 10 | ; Local declarations create a new type whenever the factory runs. |
| 11 | factory := fn(value) { |
| 12 | define-record-type(cell, make-cell(value), cell?, value(cell-value)) |
| 13 | [make-cell(value),cell?] |
| 14 | } |
| 15 | first := factory(42) |
| 16 | second := factory(42) |
| 17 | display(first[1](first[0])) |
| 18 | newline() |
| 19 | display(first[1](second[0])) |
| 20 | newline() |
| 21 | |