John M. Dlugosz has asked for the wisdom of the Perl Monks concerning the following question:

I write
my @list1= 1..5; my @list2= <a b c d e>; for each(@list1, @list2) -> $x, $y { say "$x with $y"; }
and it works as expected.

But S29 I see the example

for zip(@a;@b;@c) -> $nth_a, $nth_b, $nth_c { ... }
and when I use zip instead of each in my example, I get
1 a with 2 b 3 c with 4 d 5 e with
So what is the effective point of using ; as a parameter separator instead of comma, and why is my use of zip creating strings not lists?

—John

Replies are listed 'Best First'.
Re: [Perl6] comma vs semicolon in 'each' ?
by moritz (Cardinal) on Feb 26, 2008 at 08:45 UTC
    Pugs' behaviour was correct at the time it was implemented, but it doesn't conform ot the current status of the synopsis.

    pugs doesn't really know about the "slice" context, which is something like a non-flattening list context.

    So the S29 example is fine, although I like the infix zip ooperator Z better:

    for @a Z @b Z @c -> $x, $y, $z -> { .... }

    So whatever you do, don't confund pugs and S\d\d ;-)

      What about each? I don't see that in S29.
        Dunno.

        In Perl 6 you use %hash.kv to iterate over hashes, and if you want to interate over arrays and get the index at the same time, you use @list Z ^@list or even @list Z 0 .. *. (Note that lists are lazy, so a list of all items is essentially the same as an iterator).

        So what would you use each for?