find-integer-from ( ... i n quot: ( ... i -- ... ? ) -- ... i/f ) (original) (raw)
find-integer-from ( ... i n quot: ( ... i -- ... ? ) -- ... i/f )
Vocabulary
math
Inputs
i | an integer |
---|---|
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 i 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-integer and find.
Definition
: find-integer-from
( ... i n quot: ( ... i -- ... ? ) -- ... i/f )
2over < [
[ nip call ] 3check
[ 2drop ] [ [ 1 + ] 2dip find-integer-from ] if
] [ 3drop f ] if ; inline recursive