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

Re: RFC: Multiple-alias syntax for for

Thread Previous | Thread Next
From:
Nicolas Mendoza
Date:
June 24, 2021 13:29
Subject:
Re: RFC: Multiple-alias syntax for for
Message ID:
914140ce-10cd-c0cf-89e2-617fcbd49db5@pvv.ntnu.no
Den 24.06.2021 14:56, skrev David Nicol:
>
>
>     >     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
>
Initially I thought the idea was cool, but it seems to me after taking a 
step back that

for my ($x,y) (zip(@a,@b,@c) { … }

and

say zip(@abc,@def,@ott);

would be much clearer in the long run?

A simple mock implementation of a core zip method (without the 
multiple-alias functioning) could be:

$ perl -wle 'use List::Util; my @a = (1,2,3); @b = (qw/a b c/); sub 
zip(\@+) { return map { @{ $_ } } List::Util::zip(@_); } print zip(@a, 
@b); for my $x (zip(@a,@b)) { print $x }'
1a2b3c
1
a
2
b
3
c


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