Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

「my ($x) = …」 does not need a trailing comma, but you have to use it if there is no 「my」 (($x) = 4, 8) #5552

Open
p6rt opened this issue Aug 10, 2016 · 1 comment
Labels
RFC Request For Comments

Comments

@p6rt
Copy link

p6rt commented Aug 10, 2016

Migrated from rt.perl.org#128883 (status was 'new')

Searchable as RT128883$

@p6rt
Copy link
Author

p6rt commented Aug 10, 2016

From @AlexDaniel

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?

@p6rt p6rt added the RFC Request For Comments label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFC Request For Comments
Projects
None yet
Development

No branches or pull requests

1 participant