VocabularykernelInputs and outputs| ? | a generalized boolean |
| true | a quotation with stack effect ( ..a ? -- ..b ) |
| false | a quotation with stack effect ( ..a -- ..b ) |
Word descriptionAlternative conditional form that preserves the
cond value if it is true.
If the condition is true, it is retained on the stack before the
true quotation is called. Otherwise, the condition is removed from the stack and the
false quotation is called.
The following two lines are equivalent:
X [ Y ] [ Z ] if*
X dup [ Y ] [ drop Z ] if
ExamplesNotice how in this example, the same value is tested by the conditional, and then used in the true branch; the false branch does not need to drop the value because of how
if* works:
USING: assocs io kernel math.parser ;
IN: scratchpad
: curry-price ( meat -- price )
{
{ "Beef" 10 }
{ "Chicken" 12 }
{ "Lamb" 13 }
} at ;
: order-curry ( meat -- )
curry-price [
"Your order will be " write
number>string write
" dollars." write
] [ "Invalid order." print ] if* ;
"Deer" order-curry
Invalid order.
Definition