if-zero ( ..a n quot1: ( ..a -- ..b ) quot2: ( ..a n -- ..b ) -- ..b ) (original) (raw)

Vocabulary
math

Inputs

n a number
quot1 a quotation
quot2 a 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

USING: kernel ;

IN: math

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