{ $notes "This word is used to implement " { $link all? } "." } ;
HELP: find-integer
-{ $values { "n" integer } { "quot" { $quotation ( ... i -- ... ? ) } } { "i" { $maybe integer } } }
+{ $values { "n" integer } { "quot" { $quotation ( ... i -- ... ? ) } } { "i/f" { $maybe integer } } }
{ $description "Applies the quotation to each integer from 0 up to " { $snippet "n" } ", excluding " { $snippet "n" } ". Iteration stops when the quotation outputs a true value or the end is reached. If the quotation yields a true value for some integer, this word outputs that integer. Otherwise, this word outputs " { $link f } "." }
{ $notes "This word is used to implement " { $link find } "." } ;
HELP: find-last-integer
-{ $values { "n" integer } { "quot" { $quotation ( ... i -- ... ? ) } } { "i" { $maybe integer } } }
+{ $values { "n" integer } { "quot" { $quotation ( ... i -- ... ? ) } } { "i/f" { $maybe integer } } }
{ $description "Applies the quotation to each integer from " { $snippet "n" } " down to 0, inclusive. Iteration stops when the quotation outputs a true value or 0 is reached. If the quotation yields a true value for some integer, the word outputs that integer. Otherwise, the word outputs " { $link f } "." }
{ $notes "This word is used to implement " { $link find-last } "." } ;
: times ( ... n quot: ( ... -- ... ) -- ... )
[ drop ] prepose each-integer ; inline
-: find-integer ( ... n quot: ( ... i -- ... ? ) -- ... i )
+: find-integer ( ... n quot: ( ... i -- ... ? ) -- ... i/f )
iterate-prep (find-integer) ; inline
: all-integers? ( ... n quot: ( ... i -- ... ? ) -- ... ? )
iterate-prep (all-integers?) ; inline
-: find-last-integer ( ... n quot: ( ... i -- ... ? ) -- ... i )
+: find-last-integer ( ... n quot: ( ... i -- ... ? ) -- ... i/f )
over 0 < [
2drop f
] [