Hi,

The combine-single word has too many shuffle words for what it does; 3
shuffle words and 3 logic words is a good sign that there's a simpler
way to express the algorithm at hand.

You can get rid of the 'tuck' and one of the 'swap's using 'keep' instead:

: combine-single ( obj seq -- newseq ) [ length swap <repetition> ] keep zip ;

However there is in fact a simpler implementation of the same
algorithm that doesn't involve any shuffling at all. What you're doing
is transforming each element X of the sequence into { Y X } where Y is
a fixed value. You can express this using map:

: combine-single ( obj seq -- newseq ) [ 2array ] with map ;

Slava

On Wed, Jan 21, 2009 at 1:50 AM, Rajat Datta <[email protected]> wrote:
> Hi!  I wonder if I can get a critique of the following two words:
>
> : combine-single ( obj seq -- newseq ) tuck length swap <repetition>
> swap zip ;
> : combine-multiple ( seq seq -- newseq ) [ combine-single ] curry map
> concat [ flatten ] map ;
>
> So,  { 1 2 3 4 } dup dup combine-multiple combine-multiple will
> produce the following sequence:
>
> {
>     { 1 1 1 }   { 1 1 2 }   { 1 1 3 }   { 1 2 1 }   { 1 2 2 }   { 1 2
> 3 }   { 1 3 1 }   { 1 3 2 }   { 1 3 3 }
>     { 2 1 1 }   { 2 1 2 }   { 2 1 3 }   { 2 2 1 }   { 2 2 2 }   { 2 2
> 3 }   { 2 3 1 }   { 2 3 2 }   { 2 3 3 }
>     { 3 1 1 }   { 3 1 2 }   { 3 1 3 }   { 3 2 1 }   { 3 2 2 }   { 3 2
> 3 }   { 3 3 1 }   { 3 3 2 }   { 3 3 3 }
> }
>
> I have just started using Factor, and I'm sure I'm missing words that
> will do this more elegantly.
>
> Thanks,
>
> rajat
>
> ------------------------------------------------------------------------------
> This SF.net email is sponsored by:
> SourcForge Community
> SourceForge wants to tell your story.
> http://p.sf.net/sfu/sf-spreadtheword
> _______________________________________________
> Factor-talk mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>

------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to