You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
perl -Mexperimental=refaliasing \
-E 'my $x = [1,2,3]; \my @y = $x; say for @y'
...but the question I keep hearing is "why is the backslash on the my and not
the variable?"
The answer is not weird. It's pre-existing syntax to get a reference to a new
variable. It's still confusing, though, because people expect to be able to
write:
my \@y = $x;
I even got this question from Larry.
We should allow that. It would also be good to allow:
perl -Mexperimental=refaliasing \
-E 'my $x = [1,2,3]; \my @y = $x; say for @y'
...but the question I keep hearing is "why is the backslash on the my
and not
the variable?"
The answer is not weird. It's pre-existing syntax to get a reference
to a new
variable. It's still confusing, though, because people expect to be
able to
write:
my \@y = $x;
I even got this question from Larry.
That surprised me. After all, I was just following his existing Perl 5 syntax.
We should allow that. It would also be good to allow:
That surprised me. After all, I was just following his existing Perl
5 syntax.
I think that the feature looks so new that it's easy to forget how it's using existing syntax, especially since it's syntax one is fairly unlikely to use.
That begs the question of what
$x = my \@y;
would do. I imagine it would be the same as
$x = \my @y;
That's my thinking as well.
BTW, is anybody using for \@x (...) yet?
I believe I have used "for my \%x" a few times, if this meets your criteria. :)
* Father Chrysostomos via RT <perlbug-followup@perl.org> [2016-05-18 08:23]:
Would rvalue use of ‘my \’ be governed by the
experimental::refaliasing feature feature? Would they produce an
experimental warning?
The value of the refaliasing feature does not depend on whether the new
ref constructor syntax works out, and the new syntax may fail to work
out due to edge cases that could have nothing to do with refaliasing.
I think they should be separate experiments.
Would refaliasing automatically adopt the new syntax if it is introduced
as a general synonym for the old syntax, or would the features have to
be made to work with each other? If they are highly interdependent, then
maybe the new declare-and-ref syntax experiment ought to wait for the
conclusion of the refaliasing experiment so that each can be evaluated
separately.
* Father Chrysostomos via RT <perlbug-followup@perl.org> [2016-05-18 08:23]:
Would rvalue use of ‘my \’ be governed by the
experimental::refaliasing feature feature? Would they produce an
experimental warning?
The value of the refaliasing feature does not depend on whether the new
ref constructor syntax works out, and the new syntax may fail to work
out due to edge cases that could have nothing to do with refaliasing.
I think they should be separate experiments.
Would refaliasing automatically adopt the new syntax if it is introduced
as a general synonym for the old syntax, or would the features have to
be made to work with each other?
They would not be interdependent. In fact, the new syntax would just be a matter of switching the two tokens around in the lexer, which is kinda hard to get wrong, so I wonder whether it even needs to be experimental, except as a matter of principle.
Assuming the latter (principle), what would we call it? my_whack? (Though I usually drop the h for that slang term: my_wack.) my_refcons?
(BTW, not having it experimental would make the implementation a bit easier.)
In fact, the new syntax would just
be a matter of switching the two tokens around in the lexer
See the sprout/mywack branch. It’s a six-line patch.
Oh, but what about my(\$a, $b, \$c)? If that should be permitted, then it is not just a six-line patch, but it will still not interfere with refaliasing. And I still don’t know what to call it if it will be experimental.
* Father Chrysostomos via RT <perlbug-followup@perl.org> [2016-05-21T14:58:38]
Oh, but what about my(\$a, $b, \$c)? If that should be permitted, then it is
not just a six-line patch, but it will still not interfere with refaliasing.
I'd think so, imagining something like:
my ($self, \@arg) = @_;
And I still don’t know what to call it if it will be experimental.
On Sun May 22 18:06:43 2016, perl.p5p@rjbs.manxome.org wrote:
* Father Chrysostomos via RT <perlbug-followup@perl.org> [2016-05-
21T14:58:38]
Oh, but what about my(\$a, $b, \$c)? If that should be permitted,
then it is
not just a six-line patch, but it will still not interfere with
refaliasing.
I'd think so, imagining something like:
my ($self, \@arg) = @_;
You do realise, I hope, that $_[1] is expected to be an array ref, there?
And I still don’t know what to call it if it will be experimental.
I'm not too worried about a name. refs_in_my?
I’m been thinking of declared_refs, since it applies to the two other *declarators* as well.
I hate this syntax for exactly this type of ugly edge case. Better to
follow the data::alias syntax and introduce a new keyword.
On 22 May 2016 22:38, "Father Chrysostomos via RT" <
perlbug-followup@perl.org> wrote:
If \local $x = $foo works, then local \$x should, do.
I was half joking about delete local \$foo{bar}. That can remain a syntax error.
Better to
follow the data::alias syntax and introduce a new keyword.
Data::Alias has a smart-match-like list of which types of syntax passed to the function will result in aliasing. I don’t think we should follow that route. With \ notation, the intent is always clear. With Data::Alias, I find that not to be the case. I have tried learning how to use it, but it just confuses me.
Also, you end up with the whole issue again of whether
alias @x = @y
should alias the arrays or the individual elements. The fact that we have a distinction between \@a and \(@a) that people already know about was one of the main reasons for going with that notation.
The sprout/mywack contains what I believe is a working implementation, but it needs docs (including perldiag entries) and tests. I hope someone can take over from here, because I don’t know when I will next have time.
Things to test for:
my \$a # equivalent to \my $a
my \($a,$b) # equivalent to \my($a, $b)
my (\($a,$b)) # same
my (\$a, $b) # equivalent to (\my $a, $b)
my \$a : foo
my \$a ** 1 # should be equivalent to \my $a ** 1, which is
# \(my $a ** 1), which is an error
my \\$a # if the declarator can penetrate one backslash, it will also
# penetrate two; equiv. to \\my $a
my (\\$a)
my (\$a) :attr
foreach my \$x ($y) { ... }
ditto with state/our/local (except that local does not take attributes or work in foreach).
Note that assignment to ‘my \$a : foo’ does not currently work, except with ‘our’ (bug #128183). That is not related to the my\ syntax per se.
Hate was too strong a word. Thanks for explaining and thanks for doing this
work
Despite my crusty remark i think it is very useful.
On 23 May 2016 02:10, "Father Chrysostomos via RT" <
perlbug-followup@perl.org> wrote:
On Sun May 22 19:51:58 2016, demerphq wrote:
I hate this syntax
Are you referring to the use of backslashes?
for exactly this type of ugly edge case.
I was half joking about delete local \$foo{bar}. That can remain a syntax
error.
Better to
follow the data::alias syntax and introduce a new keyword.
Data::Alias has a smart-match-like list of which types of syntax passed to
the function will result in aliasing. I don’t think we should follow that
route. With \ notation, the intent is always clear. With Data::Alias, I
find that not to be the case. I have tried learning how to use it, but it
just confuses me.
Also, you end up with the whole issue again of whether
alias @​x = @​y
should alias the arrays or the individual elements. The fact that we have
a distinction between \@a and \(@a) that people already know about was one
of the main reasons for going with that notation.
In any case, my branch does not touch signatures, and I don’t know
when I will have time to continue with this.
Getting it working outside of signatures is still, I think, a good start.
I haven't yet had a chance to compile the branch or play with it. I hope to do so, but I'm not sure when. Hopefully someone else will also be excited to have this working.
Getting it working outside of signatures is still, I think, a good
start.
I think we should put signatures in a separate ticket, since the issues really are orthogonal. (That’s not to say they can’t be implemented at the same time.) I have opened ticket #128242.
In any case, my branch does not touch signatures, and I don’t know
when I will have time to continue with this.
Getting it working outside of signatures is still, I think, a good
start.
I haven't yet had a chance to compile the branch or play with it. I
hope to do so, but I'm not sure when. Hopefully someone else will
also be excited to have this working.
I have written some rudimentary documentation and tests for the warnings and error messages, and pushed them to the sprout/mywack branch. That’s probably it for now until next weekend (assuming I get time next weekend).
Activity
p5pRT commentedon Feb 13, 2016
From @rjbs
This is pretty useful:
perl -Mexperimental=refaliasing \
-E 'my $x = [1,2,3]; \my @y = $x; say for @y'
...but the question I keep hearing is "why is the backslash on the my and not
the variable?"
The answer is not weird. It's pre-existing syntax to get a reference to a new
variable. It's still confusing, though, because people expect to be able to
write:
my \@y = $x;
I even got this question from Larry.
We should allow that. It would also be good to allow:
my ($x, \@y, \%z) = @_;
...which means we should then allow:
sub foo ($x, \@y, \%z) { ... }
I would use the *heck* out of that feature.
--
rjbs
p5pRT commentedon Feb 13, 2016
From @cpansprout
On Fri Feb 12 19:03:22 2016, rjbs wrote:
That surprised me. After all, I was just following his existing Perl 5 syntax.
That begs the question of what
$x = my \@y;
would do. I imagine it would be the same as
$x = \my @y;
no?
BTW, is anybody using for \@x (...) yet?
--
Father Chrysostomos
p5pRT commentedon Feb 13, 2016
The RT System itself - Status changed from 'new' to 'open'
p5pRT commentedon Feb 14, 2016
From @rjbs
On Sat Feb 13 09:48:36 2016, sprout wrote:
I think that the feature looks so new that it's easy to forget how it's using existing syntax, especially since it's syntax one is fairly unlikely to use.
That's my thinking as well.
I believe I have used "for my \%x" a few times, if this meets your criteria. :)
--
rjbs
p5pRT commentedon May 18, 2016
From @cpansprout
On Sat Feb 13 18:58:46 2016, rjbs wrote:
Would rvalue use of ‘my \’ be governed by the experimental::refaliasing feature feature? Would they produce an experimental warning?
--
Father Chrysostomos
p5pRT commentedon May 21, 2016
From @ap
* Father Chrysostomos via RT <perlbug-followup@perl.org> [2016-05-18 08:23]:
The value of the refaliasing feature does not depend on whether the new
ref constructor syntax works out, and the new syntax may fail to work
out due to edge cases that could have nothing to do with refaliasing.
I think they should be separate experiments.
Would refaliasing automatically adopt the new syntax if it is introduced
as a general synonym for the old syntax, or would the features have to
be made to work with each other? If they are highly interdependent, then
maybe the new declare-and-ref syntax experiment ought to wait for the
conclusion of the refaliasing experiment so that each can be evaluated
separately.
Regards,
--
Aristotle Pagaltzis // <http://plasmasturm.org/>
p5pRT commentedon May 21, 2016
From @cpansprout
On Fri May 20 19:53:40 2016, aristotle wrote:
They would not be interdependent. In fact, the new syntax would just be a matter of switching the two tokens around in the lexer, which is kinda hard to get wrong, so I wonder whether it even needs to be experimental, except as a matter of principle.
Assuming the latter (principle), what would we call it? my_whack? (Though I usually drop the h for that slang term: my_wack.) my_refcons?
(BTW, not having it experimental would make the implementation a bit easier.)
--
Father Chrysostomos
p5pRT commentedon May 21, 2016
From @cpansprout
On Fri May 20 22:03:00 2016, sprout wrote:
See the sprout/mywack branch. It’s a six-line patch.
--
Father Chrysostomos
p5pRT commentedon May 21, 2016
From @cpansprout
On Fri May 20 22:31:49 2016, sprout wrote:
Oh, but what about my(\$a, $b, \$c)? If that should be permitted, then it is not just a six-line patch, but it will still not interfere with refaliasing. And I still don’t know what to call it if it will be experimental.
--
Father Chrysostomos
p5pRT commentedon May 23, 2016
From @rjbs
* Father Chrysostomos via RT <perlbug-followup@perl.org> [2016-05-21T14:58:38]
I'd think so, imagining something like:
my ($self, \@arg) = @_;
I'm not too worried about a name. refs_in_my?
--
rjbs
p5pRT commentedon May 23, 2016
From @cpansprout
On Sun May 22 18:06:43 2016, perl.p5p@rjbs.manxome.org wrote:
You do realise, I hope, that $_[1] is expected to be an array ref, there?
I’m been thinking of declared_refs, since it applies to the two other *declarators* as well.
--
Father Chrysostomos
p5pRT commentedon May 23, 2016
From @cpansprout
If \local $x = $foo works, then local \$x should, do.
But what about delete local \$foo{bar}?
Should I duck?
--
Father Chrysostomos
p5pRT commentedon May 23, 2016
From @demerphq
I hate this syntax for exactly this type of ugly edge case. Better to
follow the data::alias syntax and introduce a new keyword.
On 22 May 2016 22:38, "Father Chrysostomos via RT" <
perlbug-followup@perl.org> wrote:
p5pRT commentedon May 23, 2016
From @cpansprout
On Sun May 22 19:51:58 2016, demerphq wrote:
Are you referring to the use of backslashes?
I was half joking about delete local \$foo{bar}. That can remain a syntax error.
Data::Alias has a smart-match-like list of which types of syntax passed to the function will result in aliasing. I don’t think we should follow that route. With \ notation, the intent is always clear. With Data::Alias, I find that not to be the case. I have tried learning how to use it, but it just confuses me.
Also, you end up with the whole issue again of whether
alias @x = @y
should alias the arrays or the individual elements. The fact that we have a distinction between \@a and \(@a) that people already know about was one of the main reasons for going with that notation.
--
Father Chrysostomos
p5pRT commentedon May 23, 2016
From @cpansprout
The sprout/mywack contains what I believe is a working implementation, but it needs docs (including perldiag entries) and tests. I hope someone can take over from here, because I don’t know when I will next have time.
Things to test for:
my \$a # equivalent to \my $a
my \($a,$b) # equivalent to \my($a, $b)
my (\($a,$b)) # same
my (\$a, $b) # equivalent to (\my $a, $b)
my \$a : foo
my \$a ** 1 # should be equivalent to \my $a ** 1, which is
# \(my $a ** 1), which is an error
my \\$a # if the declarator can penetrate one backslash, it will also
# penetrate two; equiv. to \\my $a
my (\\$a)
my (\$a) :attr
foreach my \$x ($y) { ... }
ditto with state/our/local (except that local does not take attributes or work in foreach).
Note that assignment to ‘my \$a : foo’ does not currently work, except with ‘our’ (bug #128183). That is not related to the my\ syntax per se.
--
Father Chrysostomos
p5pRT commentedon May 23, 2016
From @rjbs
* Father Chrysostomos via RT <perlbug-followup@perl.org> [2016-05-22T21:27:10]
Yes, of course. It's only through that that you can write:
my ($self, \@arg, \%arg) = @_;
...and someday hope to land that into signatures.
That's better.
--
rjbs
p5pRT commentedon May 23, 2016
From @demerphq
Hate was too strong a word. Thanks for explaining and thanks for doing this
work
Despite my crusty remark i think it is very useful.
On 23 May 2016 02:10, "Father Chrysostomos via RT" <
perlbug-followup@perl.org> wrote:
p5pRT commentedon May 23, 2016
From @cpansprout
On Mon May 23 04:41:56 2016, perl.p5p@rjbs.manxome.org wrote:
I have just re-read your original post, which I neglected to do. I see I have made some pretty inane statements in this thread.
In any case, my branch does not touch signatures, and I don’t know when I will have time to continue with this.
--
Father Chrysostomos
p5pRT commentedon May 23, 2016
From @rjbs
On Mon May 23 12:46:35 2016, sprout wrote:
Getting it working outside of signatures is still, I think, a good start.
I haven't yet had a chance to compile the branch or play with it. I hope to do so, but I'm not sure when. Hopefully someone else will also be excited to have this working.
--
rjbs
p5pRT commentedon May 26, 2016
From @cpansprout
On Mon May 23 13:09:38 2016, rjbs wrote:
I think we should put signatures in a separate ticket, since the issues really are orthogonal. (That’s not to say they can’t be implemented at the same time.) I have opened ticket #128242.
--
Father Chrysostomos
p5pRT commentedon May 27, 2016
From @ap
* Father Chrysostomos via RT <perlbug-followup@perl.org> [2016-05-23 12:23]:
Did you really mean the following as you wrote it, or as I rewrote it?
my (\$a, $b) # equivalent to (\my $a, my $b)
Regards,
--
Aristotle Pagaltzis // <http://plasmasturm.org/>
p5pRT commentedon May 27, 2016
From @cpansprout
On Fri May 27 04:41:20 2016, aristotle wrote:
As you rewrote it.
--
Father Chrysostomos
p5pRT commentedon May 30, 2016
From @cpansprout
On Mon May 23 13:09:38 2016, rjbs wrote:
I have written some rudimentary documentation and tests for the warnings and error messages, and pushed them to the sprout/mywack branch. That’s probably it for now until next weekend (assuming I get time next weekend).
--
Father Chrysostomos
p5pRT commentedon Jul 17, 2016
From @cpansprout
I finished writing tests. My branch is now merged as 6fe925b. Signatures are unaffected. (The other ticket, #128242, remains open.)
--
Father Chrysostomos
p5pRT commentedon Jul 17, 2016
@cpansprout - Status changed from 'open' to 'pending release'
p5pRT commentedon May 30, 2017
From @khwilliamson
Thank you for filing this report. You have helped make Perl better.
With the release today of Perl 5.26.0, this and 210 other issues have been
resolved.
Perl 5.26.0 may be downloaded via:
https://metacpan.org/release/XSAWYERX/perl-5.26.0
If you find that the problem persists, feel free to reopen this ticket.
p5pRT commentedon May 30, 2017
@khwilliamson - Status changed from 'pending release' to 'resolved'