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

Prev:unless* ( ..a ? false: ( ..a -- ..a x ) -- ..a x )
Next:? ( ? true false -- true/false )


Vocabulary
kernel

Inputs and outputs
defaultan object
conda generalized boolean
truea quotation with stack effect ( ..a cond -- ..b )
falsea quotation with stack effect ( ..a default -- ..b )


Word description
If the condition is f, the false quotation is called with the default value on the stack. Otherwise, the true quotation is called with the condition on the stack.

Notes
The following two lines are equivalent:
[ X ] [ Y ] ?if dup [ nip X ] [ drop Y ] if

The following two lines are equivalent:
[ ] [ ] ?if swap or


Definition

: ?if
( ..a default cond true: ( ..a cond -- ..b ) false: ( ..a default -- ..b ) -- ..b )
pick [ drop [ drop ] 2dip call ] [ 2nip call ] if ; inline