unless-zero ( ..a n quot: ( ..a n -- ..b ) -- ..b )
Factor handbook > The language > Numbers > Mathematical functions > Arithmetic functions

Prev:when-zero ( ..a n quot: ( ..a -- ..b ) -- ..b )
Next:sgn ( x -- n )


Vocabulary
math

Inputs and outputs
na number
quotthe second quotation of an if-zero


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

Examples
This word is equivalent to if-zero with an empty first quotation:
USING: sequences math prettyprint ; 3 [ ] [ sq ] if-zero .
9

USING: sequences math prettyprint ; 3 [ sq ] unless-zero .
9


Definition


: unless-zero ( ..a n quot: ( ..a n -- ..b ) -- ..b )
[ ] swap if-zero ; inline