[plt-scheme] define-union
Stephen Bloch wrote:
> Example:
> (define-struct foo (a b))
> (define-struct bar (c d e))
> (define-union snark (foo bar number))
>
> Semantics: checks that foo, bar, and number are in fact known types,
> with one-place discriminator predicates foo?, bar?, and number?
> respectively, and does the equivalent of
> (define (snark? x)
> (if (or (foo? x) (bar? x) (number? x)))
How about modifying your spec slightly to allow this:
(define-union snark? (foo? bar? number?))
...which would allow you to use this:
(define-syntax define-union
(syntax-rules ()
((_ name (pred ...))
(define (name x) (or (pred x) ...)))))
...which has the virtue of being very simple to implement and understand.
Anton