?when ( ..a default cond: ( ..a default -- ..a new/f ) true: ( ..a new -- ..a x ) -- ..a default/x )
Factor handbook » The language » Combinators » Conditional combinators

Prev:?if ( ..a default cond: ( default -- new/f ) true: ( ..a new -- ..b ) false: ( ..a default -- ..b ) -- ..b )
Next:?unless ( ..a default cond: ( ..a default -- ..a new/f ) false: ( ..a default -- ..a x ) -- ..a default/x )


Vocabulary
kernel

Inputs
defaultan object
conda quotation with stack effect ( ..a default -- ..a new/f )
truea quotation with stack effect ( ..a new -- ..a x )


Outputs
default/xdefault or x


Word description
Calls cond on the default object and if cond outputs a new object then the true quotation is called with that new object. Otherwise, leaves the old object on the stack.

Examples
Look up an existing word or make an error pair:
USING: arrays definitions kernel math prettyprint sequences vocabs.parser ; "+" [ search ] [ where first ] ?when .
"resource:core/math/math.factor"

Try to look up a word that doesn't exist:
USING: arrays definitions kernel math prettyprint sequences vocabs.parser ; "+++++" [ search ] [ where first ] ?when .
"+++++"


See also
?if, ?unless

Definition

: ?when
( ..a default cond: ( ..a default -- ..a new/f ) true: ( ..a new -- ..a x ) -- ..a default/x )
[ ?transmute ] dip when ; inline