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

Re: RFC: Multiple-alias syntax for for

Thread Previous | Thread Next
From:
David Nicol
Date:
June 24, 2021 12:57
Subject:
Re: RFC: Multiple-alias syntax for for
Message ID:
CAFwScO_vuaqpRBZQ9FYxUeRLu0EH88Gi5fSYzBSAsGFKddoNbA@mail.gmail.com
>
> >     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

I'm pretty sure that's currently a syntax error. The risk is that the
common typo of using a semicolon instead of a comma within an array
expansion would no longer be a syntax error, which might lead to tricky and
subtle bugs, that might make it through testing phases, as the inner arrays
would need to have more than one element each before the reordering would
happen.

the undefs returned in the slots for the short arrays (if any) would be
magical L-values that when assigned to would extend the arrays they came
from.

Good morning.

-- 
"Lay off that whiskey, and let that cocaine be!" -- Johnny Cash

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