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

Re: RFC: Multiple-alias syntax for for

Thread Previous | Thread Next
From:
shmem
Date:
June 10, 2021 08:46
Subject:
Re: RFC: Multiple-alias syntax for for
Message ID:
alpine.DEB.2.21.2106101035010.10116@lvps178-77-101-18.dedicated.hosteurope.de
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.

0--gg-

-- 
_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                               /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
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