if ( ..a ? true: ( ..a -- ..b ) false: ( ..a -- ..b ) -- ..b )
Factor handbook » The language » Combinators » Conditional combinators

Next:when ( ..a ? true: ( ..a -- ..a ) -- ..a )


Vocabulary
kernel

Inputs
?a generalized boolean
truea quotation
falsea quotation


Outputs
None

Word description
If cond is f, calls the false quotation. Otherwise calls the true quotation.

The cond value is removed from the stack before either quotation is called.

Examples
USING: io kernel math ; 10 3 < [ "Math is broken" print ] [ "Math is good" print ] if
Math is good


Notes
if is executed as a primitive when preceded by two literal quotations. The below definition is not executed unless one of its arguments is a non-literal quotation, such as a quotation constructed with curry or compose, or for Fried quotations or quotations including Lexical variables.

Definition

: if
( ..a ? true: ( ..a -- ..b ) false: ( ..a -- ..b ) -- ..b )
? call ;