cond ( assoc -- )
Factor handbook » The language » Combinators » Conditional combinators

Prev:? ( ? true false -- true/false )
Next:case ( obj assoc -- )


Vocabulary
combinators

Inputs
assoca sequence of quotation pairs and an optional quotation


Outputs
None

Word description
Calls the second quotation in the first pair whose first quotation yields a true value. A single quotation will always yield a true value.

The following two phrases are equivalent:
{ { [ X ] [ Y ] } { [ Z ] [ T ] } } cond

X [ Y ] [ Z [ T ] [ no-cond ] if ] if


Errors
Throws a no-cond error if none of the test quotations yield a true value.

Examples
USING: combinators io kernel math ; 0 { { [ dup 0 > ] [ drop "positive" ] } { [ dup 0 < ] [ drop "negative" ] } [ drop "zero" ] } cond print
zero


Definition