This version won't work with an empty sequence.
Also there's already a combinator 'find' for sequences that does exactly
this:
: until ( seq quot -- ) find 2drop ; inline
Slava
Phil Dawes wrote:
> Dan, you rock. I did read this paper when it appeared on LtU (I was
> programming with gambit scheme at the time), but my fuzzy memory didn't
> light it up when I thought about iterators for factor. Good job there's
> jedi like you guys to keep things on the straight and narrow!
>
> I didn't have much time today, but I wrote an until for integer-indexed
> sequences. I don't know the multi-dispatch stuff and didn't have time to
> look it up today so haven't made this into generic function yet:
>
> : iuntil-step ( i n quot -- i n quot ? )
> [ nip call ] 3keep roll ; inline
>
> : iuntil-next ( i n quot ? -- i' n quot ? )
> >r >r >r 1+ r> r> r> ! ( i' n quot ? )
> ; inline
>
> : iuntil-test ( i n quot ? -- i n quot ?' )
> >r >r 2dup >= r> r> ! ( i' n ? quot ? )
> swapd or ! ( i n quot ? )
> ; inline
>
> : iuntil-loop ( i n quot' -- )
> iuntil-step
> iuntil-next
> iuntil-test
> [ 3drop ] [ iuntil-loop ] if ; inline
>
> : until ( seq quot -- )
> (each) ! ( n quot')
> iterate-prep ! (0 n quot')
> iuntil-loop ; inline
>
> [ 1 2 3 ]
> [ { 1 2 3 } [ f ] until ] unit-test
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk