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 23, 2021 07:04
Subject:
Re: RFC: Multiple-alias syntax for for
Message ID:
20210623070440.GL11066@etla.org
On Tue, Jun 22, 2021 at 04:03:39PM +0100, Dave Mitchell wrote:

> Just throwing this out as a possible further/later extension of this idea:
> allow for multiple lists, separated by semicolons, to be iterated over in
> parallel, to provide a more general N-from-M iteration mechanism.

It's an interesting idea, but you can't implement it with the existing OPs.
So it would belong in its own RFC, and given that it's likely tricky to
implement, and neither you nor me are interested in implementing it, I
don't think that it would go anywhere soon.

(This isn't a "no, we must never do this" - its "I don't see much benefit
in discussing it further until it looks likely that someone would write it
in a timely fashion" combined with "and if a person with the skills and time
existed, there are other improvements that gain Perl more")

> and
> 
>     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 (as you know, but most folks might not), there's
an optimisation to avoid creating a temporary list for iterating whole
arrays. So logically the first example you give ought to avoid creating
3 temporary lists, or it could get slow. Whereas the second can not.

So there's quite a lot of state and complexity needed already.

> This doesn't clash with the existing
> 
>     for (init; cond; iterate) { ...}
> 
> syntax, since that doesn't have an iterator variable.

That's an interesting observation.

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