Jonathan Scott Duff writes:
> On Tue, Jul 13, 2004 at 03:31:57PM +0200, Michele Dondi wrote:
> > Put more clearly, it is now common to see things like:
> > 
> >   for my $x (1..10) {
> >       for my $y (5..20) {
> >       for my $text (qw/foo bar baz/) {
> >           do_stgh_with $x, $y, $text;
> >       }
> >       }
> >   }
> > 
> > and it would be very much in the phylosophy of Perl to allow for a very 
> > concise syntax to obtain the same effect. I am aware of the zip operator, 
> > but AFAICT it solves an equally common but completely different problem...
> 
> Are you sure?
> 
> for zip(1..10, 5..20, <<foo bar baz>>) -> $x, $y, $text {
>    do_something_with $x,$y,$text;
> }

That does a different thing entirely.  Allow me to demonstrate, using
C<outer> that I proposed:

    for zip(1..3, 4..6) -> $x, $y {
        say "$x,$y";
    }
    1,4
    2,5
    3,6

    for outer(1..3, 4..6) -> $x, $y {
        say "$x,$y";
    }
    1,4
    1,5
    1,6
    2,4
    2,5
    2,6
    3,4
    3,5
    3,6

The essential difference between the lists that zip and outer generate
is the essential difference between the outer and inner products.  outer
expands an index while zip collapses an index.

Note also that all arguments to zip ought to be the same length (and if
not, they are finessed into bein g so), where this restriction desn't
apply to outer.

Luke

Reply via email to