develooper Front page | perl.perl5.porters | Postings from June 2021

Re: RFC: Multiple-alias syntax for for

Thread Previous | Thread Next
From:
Nicholas Clark
Date:
June 24, 2021 13:38
Subject:
Re: RFC: Multiple-alias syntax for for
Message ID:
20210624133841.GU11066@etla.org
On Thu, Jun 24, 2021 at 07:56:53AM -0500, David Nicol wrote:
> >
> > >     for my ($x, $y) (@a; @b; @c) { print "($x,$y) " }
> > >     # outputs (1,11) (111,2) (22,222) ... (5,55) (555,<undef>)
> > >
> > > and
> > >
> > >     # just to make clear that it's 3 lists, not 3 arrays;
> > >     for my $x ((7,@a); (8,@b); (9,@c)) { print "$x " }
> > >     # outputs 7 8 9 1 11 111 2 22 222  ...  5 55 555
> >
> > Implementation wise
> >
> 
> 
> What if the syntax were extended to generally allow semicolons within round
> brackets and have that mean round-robin aliasing the pieces?
> 
> my @abc = qw/ a b c /;
> my @def = qw / d e f /;
> my @ott = (1,2,3);
> 
> say (@abc;@def;@ott); # would output ad1be2cf3

Please try to stay focused. This is a thread about an RFC for `for`,
and for iterating over a single list, n-at-a-time.

Not a general syntax discussion.

(Although I approve that you're thinking about how to make syntax more
general. Good designs can be re-used, and make the language more consistent
and easier to learn. Rather too many suggested improvements are each
individual special snowflakes, with little overlap with anything else.)

`zip`ing, or whatever we'd call it, is a reasonable idea, but belongs as its
own RFC (and it's not clear to me that anyone is likely to implement it in
the near future).

Nicholas Clark

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About