when-zero ( ... n quot: ( ... -- ... x ) -- ... x ) (original) (raw)

Vocabulary
math

Inputs

n a number
quot the first quotation of an if-zero

Outputs

x an object

Word description
Makes an implicit check if the number is zero. A zero is dropped and the quot is called.

Examples
This word is equivalent to if-zero with an empty second quotation:

USING: math prettyprint ; 0 [ 4 ] [ ] if-zero .
4

USING: math prettyprint ; 0 [ 4 ] when-zero .
4

See also
if-zero, unless-zero, until-zero

Definition

IN: math

: when-zero ( ... n quot: ( ... -- ... x ) -- ... x )
[ ] if-zero ; inline