Skip Menu |
Report information
Id: 128883
Status: new
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: alex.jakimenko [at] gmail.com
Cc:
AdminCc:

Severity: (no value)
Tag: (no value)
Platform: (no value)
Patch Status: (no value)
VM: (no value)



Subject: [RFC] 「my ($x) = …」 does not need a trailing comma, but you have to use it if there is no 「my」 (($x) = 4, 8)
First, let's see how it works in Perl 5:

Command:
$ perl -wE 'my ($x) = (42, 69); say $x'

Result:
42

Command:
$ perl -wE 'my $x; ($x) = (42, 69); say $x'

Result:
42


OK. Now let's try the same thing in Perl 6:

Command:
$ perl6 -e 'my ($x) = (42, 69); say $x'

Result:
42

Command:
$ perl6 -e 'my $x; ($x) = (42, 69); say $x'

Result:
(42 69)


Whoops! Sounds like a potential pitfall.

So how can we make it work? Well, you have to use a trailing comma:


Command:
$ perl6 -e 'my $x; ($x,) = (42, 69); say $x'

Result:
42


Here comes the big question: why is the trailing comma not required when you use 「my」?

If it is done for perl 5 compatibility (kinda), then why go half way and not introduce yet another special case for assignment without 「my」?

Perhaps it is not possible at all due to how perl 6 parsed? If so, why introduce a pitfall by allowing it in 「my」?

In other words, I propose these two solutions:
1. Make 「($x) = …」 DWIM. If not possible, see solution #2
2. Throw a compile-time warning if something like 「my ($x)」 is encountered (“… in Perl 6 please use a trailing comma” or something along the lines)



I've stumbled upon this problem when I was refactoring some code. Basically, I moved 「my」 somewhere else and the code stopped working, oops! Definitely LTA.


09:24:44 <AlexDaniel> anyway, I'm submitting an RFC rakudo ticket. Feel free to throw your tomatoes at me there
09:27:25 <Xliff> AlexDaniel, if I throw anything, it will be lots in with you.
09:27:48 <Xliff> You have no idea how many hours I wasted on that (alleged) bug on my first P6 project.


This is one of those problems that we can probably solve with lots of warnings in the documentation, but why not make the language more consistent instead?


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org