Struct-type properties with a struct-like interface
define-struct-like-struct-type-property
7.0

Struct-type properties with a struct-like interface

 (require struct-like-struct-type-property)
  package: struct-like-struct-type-property

syntax

(define-struct-like-struct-type-property name [field ...])

Defines these identifiers:

The property prop:name expects a function that takes a "self" argument and returns a name result. When someone wants to use the value as a prop:name, this function should construct a more basic structure that contains the field values.

Examples:
> (require struct-like-struct-type-property)
> (define-struct-like-struct-type-property foo [a b c])
> (foo-a (foo 1 2 3))

1

> (foo? (foo "a" "b" "c"))

#t

> (struct bar [x]
    #:property prop:foo ; when a bar is used as a foo, do this
    (lambda (self)
      (foo (first (bar-x self))
           (second (bar-x self))
           (third (bar-x self)))))
> (foo-a (bar (list 4 5 6)))

4

> (foo? (bar (list 'd 'e 'f)))

#t

> (match (bar (list 1 3 5))
    [(foo a b c) c])

5