if-zero ( ..a n quot1: ( ..a -- ..b ) quot2: ( ..a n -- ..b ) -- ..b )
Factor handbook » The language » Numbers » Mathematical functions » Arithmetic functions

Prev:between? ( x min max -- ? )
Next:when-zero ( ... n quot: ( ... -- ... x ) -- ... x )


Vocabulary
math

Inputs
na number
quot1a quotation
quot2a quotation


Outputs
None

Word description
Makes an implicit check if the number is zero. A zero is dropped and quot1 is called. Otherwise, if the number is not zero, quot2 is called on it.
USING: kernel math prettyprint sequences ; 3 [ "zero" ] [ sq ] if-zero .
9


See also
when-zero, unless-zero, until-zero

Definition


: if-zero
( ..a n quot1: ( ..a -- ..b ) quot2: ( ..a n -- ..b ) -- ..b )
[ dup zero? ] [ [ drop ] prepose ] [ ] tri* if ; inline