Raku / old-issue-tracker

Tickets from RT
https://github.com/Raku/old-issue-tracker/issues
2 stars 1 forks source link

make :%hash<key> a pair constructor #4997

Open p6rt opened 8 years ago

p6rt commented 8 years ago

Migrated from rt.perl.org#127165 (status was 'open')

Searchable as RT127165$

p6rt commented 8 years ago

From @FROGGS

For a while we can create Pairs from named captures of match variables​: m​: my %hash = key => 42; say (​:$\) rakudo-moar ac4f9f​: OUTPUT«key => Nil␤»

Sadly, this does not even parse​: m​: my %hash = key => 42; say (​:$/\) rakudo-moar ac4f9f​: OUTPUT«===SORRY!=== Error while compiling /tmp/3GMq24eXRj␤Bogus statement␤at /tmp/3GMq24eXRj​:1␤------> my %hash = key => 42; say (​:$⏏/\)␤ expecting any of​:␤ colon pair␤»

Nor does this create a Pair​: m​: my %hash = key => 42; say (​:%hash\) rakudo-moar ac4f9f​: OUTPUT«(Mu)␤»

So I vote for all shown statements to create a Pair of key => Nil or key => Any respectively.

Funnily, Arrays behave differently when used with colonpair syntax​: m​: my @​array = 42, 43; say (​:@​array[0]) rakudo-moar ac4f9f​: OUTPUT«array => [42 43]␤»

Which is also wrong, IMO. This case should either produce 0 => 42, or array => 42. If we go for the latter then the shown Hashes should also be treated as subscripts, and produce hash => 42, if the variable is not anonymous like in $/\ or $\. This would allow %hash\, but then again $\ and $/\<key foo> need to parsefail.

p6rt commented 8 years ago

From @LLFourn

Is the first example meant to be like​:

'"foo" ~~ /$\=.+/; say (​:$\)'

??

On Tue, Jan 5, 2016 at 6​:42 PM Tobias Leich \perl6\-bugs\-followup@&#8203;perl\.org wrote​:

# New Ticket Created by Tobias Leich # Please include the string​: [perl #​127165] # in the subject line of all future correspondence about this issue. # \<URL​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=127165 >

For a while we can create Pairs from named captures of match variables​: m​: my %hash = key => 42; say (​:$\) rakudo-moar ac4f9f​: OUTPUT«key => Nil␤»

Sadly, this does not even parse​: m​: my %hash = key => 42; say (​:$/\) rakudo-moar ac4f9f​: OUTPUT«===SORRY!=== Error while compiling /tmp/3GMq24eXRj␤Bogus statement␤at /tmp/3GMq24eXRj​:1␤------> my %hash = key => 42; say (​:$⏏/\)␤ expecting any of​:␤ colon pair␤»

Nor does this create a Pair​: m​: my %hash = key => 42; say (​:%hash\) rakudo-moar ac4f9f​: OUTPUT«(Mu)␤»

So I vote for all shown statements to create a Pair of key => Nil or key => Any respectively.

Funnily, Arrays behave differently when used with colonpair syntax​: m​: my @​array = 42, 43; say (​:@​array[0]) rakudo-moar ac4f9f​: OUTPUT«array => [42 43]␤»

Which is also wrong, IMO. This case should either produce 0 => 42, or array => 42. If we go for the latter then the shown Hashes should also be treated as subscripts, and produce hash => 42, if the variable is not anonymous like in $/\ or $\. This would allow %hash\, but then again $\ and $/\<key foo> need to parsefail.

p6rt commented 8 years ago

The RT System itself - Status changed from 'new' to 'open'

p6rt commented 8 years ago

From @FROGGS

Yes, that's how you get a Match variable.

p6rt commented 8 years ago

From @LLFourn

I was confused because of the preceding hash assignment :)

I also find myself not wanting to do { long-attribute-name => $obj.long-attribute-name }. Maybe $obj.=>long-attribute-name could DWIM and :$obj.my-val becomes ('obj' => 'my-val result').

I'll be quiet now.

On Tue, Jan 5, 2016 at 7​:01 PM Tobias Leich \email@&#8203;froggs\.de wrote​:

Yes, that's how you get a Match variable.