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

Re: RFC: Multiple-alias syntax for for

Thread Previous | Thread Next
From:
Dan Book
Date:
June 10, 2021 08:49
Subject:
Re: RFC: Multiple-alias syntax for for
Message ID:
CABMkAVXZJiAHAEywUJwiUSsj9TGvv2BjGUXXu9kzXs=LE6kdkQ@mail.gmail.com
On Thu, Jun 10, 2021 at 4:46 AM shmem <gm@qwurx.de> wrote:

> From the keyboard of Dan Book [10.06.21,04:24]:
>
> >       > for my ($a, $b, undef) ((1,2,3)) { … } # one iteration or syntax
> error--
> >
> >       Right. This is the interesting question...
> >
> >       I'm suggesting syntax error.
> >
> >       I think the slightly better question would be express it as
> >
> >           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).
> >
> >       I'd like to stick to forbidding this, because it makes the
> implementation
> >       harder.
> >
> >
> > I also see how it could be useful, but on the other hand it is exactly
> the same in practice
> > as my ($x, $y, $z) but with some (imagined or real) microoptimization of
> not aliasing the
> > second value/using up that variable name. I don't think it's useful
> enough to outweigh
> > complication to the implementation.
>
> And it would introduce an exception of a general rule for little gain.
> Targets for assignments must be lvalues. Assigning to undef, a literal
> or a constant is prohibited.
>
> If assigning to 'undef' in that special case is permitted, the following
> should also be permitted
>
> for my ($first, "banana", $last) (@snacks) { ... }
>
> and so the "must be lvalue" rule would deteriorate from that end.


Well, it is already a special case in list assignment for this purpose,
which is probably where the idea came from:

my ($x, undef, $z) = @stuff;

But so are a bunch of other things that don't make sense in this context.

-Dan

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