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

Re: RFC: Multiple-alias syntax for for

Thread Previous | Thread Next
June 10, 2021 09:16
Re: RFC: Multiple-alias syntax for for
Message ID:
On 10/6/21 10:06, Nicholas Clark wrote:

 > +### Permit `undef` in the list of scalars
 > +
 > +    for my ($a, undef, $c) (1 .. 9) { ... }
 > +
 > +It's a reasonable generalisation of list assignment, where you can 
assign to undef to mean "ignore this value". I can see that this 
**might** be useful.  It's also safe syntax to implement (although I 
didn't try, and I'm not sure how hard it would be).
 > +
 > +But it adds considerable runtime complexity. The easiest 
implementation is if there are exactly *n* scalars, all declared in the 
`for` loop itself, because this way they occupy adjacent Pad slots. This 
means that there is only one extra integer to store in the optree, which 
used both to calculate the *n*-at-a-time **and** the addresses of the 
target variables.
 > +
 > +Adding `undef` to the mix rules out a simple, clear implementation.

Can you just add a dummy variable there so that internally

     for my ($foo, undef, $bar) (@a) {...}

is converted in something similar to

     for my ($foo, $hidden_variable, $bar) (@a) {...}


Just for the sake of being consistent.

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About