7.7
struct-define: Short-hand accessors for struct fields
(require struct-define) | package: struct-define |
struct-define provides a short-hand way of accessing the fields of structu by the name used in the definition of the structure.
syntax
(struct-define some-struct some-instance)
If
some-struct is defined with (struct some-struct (f0 ... fN)), then defines f0 (through fN) as macros
that expand to (some-struct-f0 some-instance). If a field
f0 is mutable, then (set! f0 x) expands to
(set-some-struct-f0! some-instance x). (Note: This
explanation implies that struct-define makes assumption about
the name of the accessors, but it actually uses whatever the real
identifiers embedded in the static struct record.)
syntax
(define-struct-define the-struct-define the-struct)
Defines
the-struct-define such that (the-struct-define the-instance) expands to (struct-define the-struct the-instance).
Examples:
> (require struct-define) > (struct pie (flavor [temp #:mutable])) > (define p1 (pie 'cherry 'warm)) > (list (pie-flavor p1) (pie-temp p1)) '(cherry warm)
> (let () (struct-define pie p1) (list flavor temp)) '(cherry warm)
> (define-struct-define pie-define pie)
> (let () (pie-define p1) (set! temp 'cold) (list flavor temp)) '(cherry cold)
> (list (pie-flavor p1) (pie-temp p1)) '(cherry cold)