On Tue, Nov 05, 2002 at 03:21:54PM +1100, Damian Conway wrote:
> Larry wrote:
> > But let's keep it
> > out of the signature, I think.  In other words, if something like
> > 
> >     for @x ∥ @y ∥ @z -> $x, $y, $z { ... }
> > 
> > is to work, then
> > 
> >     @result = @x ∥ @y ∥ @z;
> > 
> > has to interleave @x, @y, and @z.  It's not special to the C<for>.
> 
> Very nice. The n-ary "zip" operator.

Um ... could we have a zip functor as well?  I think the common case
will be to pull N elements from each list rather than N from one, M
from another, etc.  So, in the spirit of timtowtdi:

        for zip(@a,@b,@c) -> $x,$y,$z { ... }           # one at a time
        for zip(@a,@b,@c,3) -> $x,$y,$z { ... }         # three at a time

zip() would interleave its array arguments one at a time by
default and N at a time if the last argument is a number.  Then the
RHS of the arrow just tells perl (and us) how many things to pull from
the resultant list.  This would, of course, lead to strange things
like this though:

        for zip(@a,@b,2) -> $x,$y,$z { ... }

but perl is always giving us enough rope.  Besides ... someone may
want/need those semantics.

> Or perhaps just:
> 
>       sub take(int $n, *@from) {
>           yield splice @from, 0, $n while @from > $n;
>           return ( @from, undef xx ($n-@from) )
>       }
> 
>       &three = &take.assuming(n=>3);
> 
>       for three(@x), three(@y), three($z) -> $x, $y, $z { ... }

Or if we generalized zip() a little:

        for weave(@a,2,@b,1) -> $x,$y,$z { ... }

Which would take 2 elements from @a, and one from @b, until both
arrays were exhausted.

I'm just casting for alternatives to the punctuative versions in case
I hit something that's really good :-)

-Scott
-- 
Jonathan Scott Duff
[EMAIL PROTECTED]

Reply via email to