On this page:
variant?
variant
variant-value
variant-tag
7.3

20 Variants

 (require rebellion/variant) package: rebellion

A variant is a value tagged with a keyword. Variants are used to distinguish different kinds of values by name, without knowing anything about the types of those values.

procedure

(variant? v)  variant?

  v : any/c
A predicate for variants.

procedure

(variant #:<kw> v)  variant?

  v : any/c
Constructs a variant containing v tagged with the given keyword, where #:<kw> stands for any keyword.

Examples:
> (variant #:success 42)

(variant #:success 42)

> (variant #:failure 'oops)

(variant #:failure 'oops)

procedure

(variant-value var)  any/c

  var : variant?
Returns the value contained in var.

Examples:
> (variant-value (variant #:success 42))

42

> (variant-value (variant #:failure 'oops))

'oops

procedure

(variant-tag var)  keyword?

  var : variant?
Returns the tag keyword of var.

Examples:
> (variant-tag (variant #:success 42))

'#:success

> (variant-tag (variant #:failure 'oops))

'#:failure