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 10, 2021 09:39
Subject:
Re: RFC: Multiple-alias syntax for for
Message ID:
20210610093937.GB16703@etla.org
On Thu, Jun 10, 2021 at 11:16:25AM +0200, Salvador FandiƱo wrote:
> 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) {...}

Yes, I think it would be possible, and probably the simplest solution.
It added complication. *I* didn't want to, as it added complication.

> ?
> 
> Just for the sake of being consistent.

Yes, this is a trade off. *I* didn't think that it was worth it.
I'm not familiar enough with the grammar generally to know how to do this
easily, and I think that the optree generation would also become more
complicated.

Given that we already forbid arrays and hashes in the list of lexicals
we are declaring, it's already "inconsistent" with what my (...) = (...);
permits, so I'm not sure if we really are removing inconsistency if we
did the work to permit undef too.

Yes, this is subjective. And I might not be correct.

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