Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[perl #117985] [BUG] :p adverb on hash lookup doesn't weed out a nonexistent hash key if it's the only key in Rakudo

3 views
Skip to first unread message

Carl Mäsak

unread,
May 13, 2013, 2:54:38 PM5/13/13
to bugs-bi...@rt.perl.org
# New Ticket Created by "Carl Mäsak"
# Please include the string: [perl #117985]
# in the subject line of all future correspondence about this issue.
# <URL: https://rt.perl.org:443/rt3/Ticket/Display.html?id=117985 >


<lizmat> r: my %a= (a => 1, b => 2); say %a<c>:p # shouldn't this be Nil ?
<camelia> rakudo 2a04f2: OUTPUT«"c" => Any␤»
<masak> lizmat: yeah, think so.
* masak submits rakudobug
<masak> r: my %a= (a => 1, b => 2); say %a<a b c>:p
<camelia> rakudo 2a04f2: OUTPUT«"a" => 1 "b" => 2 ␤»
<masak> weird.
<lizmat> different candidates ?
<jnthn> yeah
<lizmat> single key handled by multi method postcircumfix:<{ }>(\SELF:
Mu $key, :$p!)
<lizmat> multi key handled by multi method postcircumfix:<{ }>(\SELF:
Positional \key, :$p!)

Patrick R. Michaud

unread,
May 13, 2013, 4:21:10 PM5/13/13
to perl6-c...@perl.org
On Mon, May 13, 2013 at 11:54:38AM -0700, Carl Mäsak wrote:
> <lizmat> r: my %a= (a => 1, b => 2); say %a<c>:p # shouldn't this be Nil ?
> <camelia> rakudo 2a04f2: OUTPUT«"c" => Any␤»
> <masak> lizmat: yeah, think so.
> * masak submits rakudobug

I'm pretty sure rakudo is correct in this case.
We know that %a<c> should return a value with a vivifying
WHENCE property (for assignment), so the only question is
what value it should return.

In particular, "my %h;" is like saying "my Any %h", in that the hash
is a set of Scalar containers that default to "Any". If the declaration
were "my Int %h", then I'd expect %h<c> to return "Int".


> <masak> r: my %a= (a => 1, b => 2); say %a<a b c>:p
> <camelia> rakudo 2a04f2: OUTPUT«"a" => 1 "b" => 2 ␤»

This is a legitimate bug, IMO.
I think there should be a "c" => Any pair returned here,
where the Any has a WHENCE clause to autovivify the hash
entry. Again, consider %a<a b c> = 4..6;

Pm

Christian Bartolomaeus via RT

unread,
Jan 14, 2015, 3:30:03 PM1/14/15
to perl6-c...@perl.org
This ticket is related to https://rt.perl.org/Ticket/Display.html?id=117935.
The current behaviour seems to be in line with today's design documents (http://design.perl6.org/S02.html#Subscript_adverbs).

$ perl6 -e 'my %a= (a => 1, b => 2); say %a<c>:p'

$ perl6 -e 'my %a= (a => 1, b => 2); say %a<a b c>:p'
a => 1 b => 2

One can negate the adverb to get the key/value pair for nonexistent keys:

$ perl6 -e 'my %a= (a => 1, b => 2); say %a<c>:!p'
c => (Any)
$ perl6 -e 'my %a= (a => 1, b => 2); say %a<a b c>:!p'
a => 1 b => 2 c => (Any)

Since there are passing tests for this behaviour in roast, I'm closing this ticket now.
0 new messages