That's an interesting way of doing flatten. Just to be unambiguous, here's the change to make it work with current Factor: put a tuck before push. I wrote the above flatten code mostly as a maybe-useful example of the usage of deep-subset. Modulo stack shuffles, when you inline all of the combinators the two pieces of code do the same thing.
Dan On Mon, Mar 3, 2008 at 5:16 PM, Eduardo Cavazos <[EMAIL PROTECTED]> wrote: > Hello, > > There's a word called 'flatten' which flattens sequences. > > Here's the implementation of 'flatten' from sequences.deep : > > ---------------------------------------------------------------------- > : deep-each ( obj quot -- ) > [ call ] 2keep over branch? > [ [ deep-each ] curry each ] [ 2drop ] if ; inline > > : deep-subset ( obj quot -- seq ) > over >r > pusher >r deep-each r> > r> dup branch? [ like ] [ drop ] if ; inline > > : flatten ( obj -- seq ) > [ branch? not ] deep-subset ; > ---------------------------------------------------------------------- > > Here's another version of flatten. One difference is that it uses a 'push' > with effect ( vec obj -- vec ). It also doesn't maintain the type of the > sequences. > > ---------------------------------------------------------------------- > : push-or-transfer ( vec obj -- vec ) > dup branch? > [ transfer ] > [ push ] > if ; > > : transfer ( vec seq -- vec ) [ push-or-transfer ] each ; > > : flatten ( seq -- seq ) [ length <vector> ] [ ] bi transfer ; > ---------------------------------------------------------------------- > > Ed > > ------------------------------------------------------------------------- > 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 > ------------------------------------------------------------------------- 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
