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

Re: RFC: Multiple-alias syntax for for

Thread Previous | Thread Next
From:
=?UTF-8?Q?Salvador_Fandi=c3=b1o?=
Date:
June 10, 2021 09:16
Subject:
Re: RFC: Multiple-alias syntax for for
Message ID:
02b76d5a-ffa2-fc39-19b2-437874a498cd@gmail.com
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


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About