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 and outputs
na number
quot1a quotation
quot2a quotation


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


Definition


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