find-integer ( ... n quot: ( ... i -- ... ? ) -- ... i/f ) (original) (raw)

Vocabulary
math

Inputs

n an integer
quot a quotation with stack effect ( ... i -- ... ? )

Outputs

i/f an integer or f

Word description
Applies the quotation to each integer from 0 up to n, excluding 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 f.

Notes
This word is used to implement find.

Definition

USING: kernel ;

IN: math

: find-integer ( ... n quot: ( ... i -- ... ? ) -- ... i/f )
[ 0 ] 2dip find-integer-from ; inline