find-last-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 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 f.
Notes
This word is used to implement find-last.
Definition
: find-last-integer
( ... n quot: ( ... i -- ... ? ) -- ... i/f )
over 0 <
[ 2drop f ] [
[ call ] 2check
[ drop ] [ [ 1 - ] dip find-last-integer ] if
] if ; inline recursive