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:12
Subject:
Re: RFC: Multiple-alias syntax for for
Message ID:
20210623071159.GM11066@etla.org
On Tue, Jun 22, 2021 at 03:04:31PM -0400, Uri Guttman wrote:
> On 6/22/21 2:58 PM, Ricardo Signes wrote:
> > On Tue, Jun 22, 2021, at 2:07 PM, David Nicol wrote:
> > > 
> > > Don't recall seeing this case discussed:
> > > 
> > >               my @iters = (undef,undef); # empty list would be
> > > run-time error!
> > >               for @iters ( @iterees) {
> > >                     ... #   $iters[0] is alias to even iterees,
> > > $iters[1] is alias to odd ones
> > >                     # if @iters changes size, next time through it
> > > gets that many
> > >              }
> > 
> > It's not legal.  The thing after "for" must be a parenthesized list of
> > scalar targets.
> > 
> 
> but an easy workaround is this (my guess):
> 
> for ( $iters[0], $iters[1] ) ( @iterees) {
> 
> or even with the expansion??:
> 
> for ( @iters[*] ) ( @iterees) {

None of this is easy to add to the current implementation of 1-at-a-time
foreach loops.

I'm not convinced that it's a good idea making the step size of the iteration
be dependant on the array's current size, as this feels like
action-at-a-distance.

The target(s) of a foreach loop is an alias, not an assignment - to be
consistent with this:

$ perl -E 'my $foo = "Hello"; for $foo ("Boo!") { say $foo; say \$foo } say $foo; say \$foo'
Boo!
SCALAR(0x559598381f38)
Hello
SCALAR(0x5595983721b0)

it's unclear whether the the existing *values* of the array would be what
was aliased, or the entire array.

I don't think that this discussion is heading in any direction that can
be implemented.

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