match ( branches -- quot )
Algebraic data types

Prev:variant-class


Vocabulary
variants

Inputs and outputs
branchesan array


Word description
Dispatches on the type of the value on the top of the stack. If the type is a singleton-class, the corresponding quotation is called with the underlying stack unchanged. If the type is a tuple-class, the tuple slots are pushed onto the stack by order of arguments.

Examples
USING: kernel math prettyprint variants ; IN: scratchpad VARIANT: list nil cons: { { first object } { rest list } } ; : list-length ( list -- length ) { { nil [ 0 ] } { cons [ nip list-length 1 + ] } } match ; 1 2 3 4 nil <cons> <cons> <cons> <cons> list-length .
4


See also
VARIANT:, variant-class

Definition