Skip Menu |
Report information
Id: 127165
Status: open
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: FROGGS.de <email [at] froggs.de>
Cc:
AdminCc:

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



Date: Tue, 5 Jan 2016 08:42:11 +0100
From: Tobias Leich <email [...] froggs.de>
To: rakudobug [...] perl.org
Subject: [FEATURE] make :%hash<key> a pair constructor
Download (untitled) / with headers
text/plain 1.1k
For a while we can create Pairs from named captures of match variables: m: my %hash = key => 42; say (:$<key>) rakudo-moar ac4f9f: OUTPUT«key => Nil␤» Sadly, this does not even parse: m: my %hash = key => 42; say (:$/<key>) rakudo-moar ac4f9f: OUTPUT«===SORRY!=== Error while compiling /tmp/3GMq24eXRj␤Bogus statement␤at /tmp/3GMq24eXRj:1␤------> my %hash = key => 42; say (:$⏏/<key>)␤ expecting any of:␤ colon pair␤» Nor does this create a Pair: m: my %hash = key => 42; say (:%hash<key>) 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 $/<key> or $<key>. This would allow %hash<key foo>, but then again $<key foo> and $/<key Show quoted text
foo> need to parsefail.
From: Lloyd Fournier <lloyd.fourn [...] gmail.com>
To: perl6-compiler [...] perl.org, bugs-bitbucket [...] rt.perl.org
Subject: Re: [perl #127165] [FEATURE] make :%hash<key> a pair constructor
Date: Tue, 05 Jan 2016 07:56:51 +0000
Download (untitled) / with headers
text/plain 1.5k
Is the first example meant to be like:

'"foo" ~~ /$<key>=.+/; say (:$<key>)'

??



On Tue, Jan 5, 2016 at 6:42 PM Tobias Leich <perl6-bugs-followup@perl.org> wrote:
Show quoted text
# 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.perl.org/Ticket/Display.html?id=127165 >


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

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

Nor does this create a Pair:
m: my %hash = key => 42; say (:%hash<key>)
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 $/<key> or $<key>.
This would allow %hash<key foo>, but then again $<key foo> and $/<key
foo> need to parsefail.

Subject: Re: [perl #127165] [FEATURE] make :%hash<key> a pair constructor
Date: Tue, 5 Jan 2016 09:01:22 +0100
From: Tobias Leich <email [...] froggs.de>
To: Lloyd Fournier <lloyd.fourn [...] gmail.com>, perl6-compiler [...] perl.org, bugs-bitbucket [...] rt.perl.org
Yes, that's how you get a Match variable.
To: Tobias Leich <email [...] froggs.de>, perl6-compiler [...] perl.org, bugs-bitbucket [...] rt.perl.org
From: Lloyd Fournier <lloyd.fourn [...] gmail.com>
Subject: Re: [perl #127165] [FEATURE] make :%hash<key> a pair constructor
Date: Tue, 05 Jan 2016 08:17:18 +0000
Download (untitled) / with headers
text/plain 386b
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@froggs.de> wrote:
Show quoted text
Yes, that's how you get a Match variable.


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