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

Owner: Nobody
Requestors: comdog <brian.d.foy [at] gmail.com>
Cc:
AdminCc:

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



Date: Sun, 28 May 2017 14:56:06 -0400
From: brian d foy <brian.d.foy [...] gmail.com>
To: rakudobug [...] perl.org
Subject: %() creates a Map
Download (untitled) / with headers
text/plain 589b
It looks like %() with no characters between the parens creates a Map, but if there's at least one character between the parens, it creates a Hash. I figure all of these should create a Hash: my %hash = %(); put '1: ', %hash.^name; # 1: Hash my $hash-empty = %(); put '2: ', $hash-empty.^name; # 2: Map my $hash-space = %( ); put '3: ', $hash-space.^name; # 3: Hash Where is %() documented (other than examples using it)? $ perl6 -v This is Rakudo version 2017.04.3 built on MoarVM version 2017.04-53-g66c6dda implementing Perl 6.c.
From: Elizabeth Mattijsen <liz [...] dijkmat.nl>
To: "brian d foy (via RT)" <perl6-bugs-followup [...] perl.org>
Date: Sun, 28 May 2017 21:09:21 +0200
Subject: Re: [perl #131392] %() creates a Map
Download (untitled) / with headers
text/plain 874b
Show quoted text
> On 28 May 2017, at 20:56, brian d foy (via RT) <perl6-bugs-followup@perl.org> wrote: > > # New Ticket Created by "brian d foy" > # Please include the string: [perl #131392] > # in the subject line of all future correspondence about this issue. > # <URL: https://rt.perl.org/Ticket/Display.html?id=131392 > > > > It looks like %() with no characters between the parens creates a > Map, but if there's at least one character between the parens, it > creates a Hash. I figure all of these should create a Hash: > > my %hash = %(); > put '1: ', %hash.^name; # 1: Hash > > my $hash-empty = %(); > put '2: ', $hash-empty.^name; # 2: Map > > my $hash-space = %( ); > put '3: ', $hash-space.^name; # 3: Hash
FWIW, I have not been able to reproduce it, not on 2017.04.3 or HEAD or even 2015.12. So I find all of this rather strange :-)
RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 849b
On Sun, 28 May 2017 11:56:51 -0700, comdog wrote: Show quoted text
> It looks like %() with no characters between the parens creates a > Map, but if there's at least one character between the parens, it > creates a Hash. I figure all of these should create a Hash: > > my %hash = %(); > put '1: ', %hash.^name; # 1: Hash > > my $hash-empty = %(); > put '2: ', $hash-empty.^name; # 2: Map > > my $hash-space = %( ); > put '3: ', $hash-space.^name; # 3: Hash > > Where is %() documented (other than examples using it)? > > $ perl6 -v > This is Rakudo version 2017.04.3 built on MoarVM version 2017.04-53- > g66c6dda > implementing Perl 6.c.
Failing to reproduce this on any of the versions, including the one mentioned in OP. Is this being run in REPL? Do you have some modules loaded? (if in REPL, do you have Readline or Linenoise installed?)
Download (untitled) / with headers
text/plain 505b
The token `%()` isn't an empty hash, it's a synonym for `%$/` or `$/.hash`. 'foo' ~~ /$<bar>=.*/; say %(); # Map.new((:bar(Match.new... Similarly, `@()` is a synonym for `@$/` or `$/.list`. ---- These tokens are documented at https://docs.perl6.org/language/variables#index-entry-variable_%24%3Cnamed%3E-variable_%2525%28%29-Named_Attributes ---- If there hasn't been significant adoption of these tokens in extant code then I'd personally +1 deprecation of them in v6.d in favor of `%$/` and `@$/`.
RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 492b
On Sun, 28 May 2017 18:18:14 -0700, raiph wrote: Show quoted text
> If there hasn't been significant adoption of these tokens in extant code then I'd personally +1 deprecation of them in v6.d in favor of `%$/` and `@$/`.
+1. Even knowing $() was special, it didn't occur to me %() and @() could be special too. While $() saves some typing, the %() vs %$/ are no win IMO. I listed removal as a proposal in 6.d doc: https://github.com/perl6/specs/blob/master/v6d.pod Renaming this ticket to @LARRY/6.d RFC
Date: Mon, 29 May 2017 12:26:32 -0400
To: perl6-bugs-followup [...] perl.org
From: brian d foy <brian.d.foy [...] gmail.com>
Subject: Re: [perl #131392] %() creates a Map
Download (untitled) / with headers
text/plain 416b
I did pull my first example out of a slightly larger program I was playing with, but I thought that a match would surely have no effect. Stupid me, because I've been around long enough to know that assumption is almost always false. That "harmless" thing you leave out is the actual problem. Here's a complete program that reproduces it: 'abcdef' ~~ m/ cd /; my $thingy = %(); put $thingy.^name; #Map
Subject: Re: [perl #131392] %() creates a Map
Date: Mon, 29 May 2017 18:50:44 +0200
From: Elizabeth Mattijsen <liz [...] dijkmat.nl>
To: "brian d foy (via RT)" <perl6-bugs-followup [...] perl.org>
Download (untitled) / with headers
text/plain 816b
Show quoted text
> On 29 May 2017, at 18:26, brian d foy <brian.d.foy@gmail.com> wrote: > I did pull my first example out of a slightly larger program I was > playing with, but I thought that a match would surely have no effect. > Stupid me, because I've been around long enough to know that > assumption is almost always false. That "harmless" thing you leave out > is the actual problem. Here's a complete program that reproduces it: > > 'abcdef' ~~ m/ cd /; > > my $thingy = %(); > put $thingy.^name; #Map
Well, do we consider the named matches of a match modifiable or not? Feels to me having it as an (immutable) Map feels actually closer to the intent, rather than it being a (modifiable) Hash. It also gives more opportunity for optimization. So perhaps the Hashes should be considered the odd ones out? Liz


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