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

[perl #117935] [BUG] Sending named parameter ;p with value 0 to .postfix:<{ }> should yield the value and not the pair in Rakudo

4 views
Skip to first unread message

Carl Mäsak

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


<lizmat> rn: my %h= (:a<1>); say %h.postcircumfix:<{ }>("a", p => 0 )
<camelia> rakudo fe7049: OUTPUT«"a" => "1"␤»
<camelia> ..niecza v24-45-gbf8d2ad: OUTPUT«"a" => 1␤»
* lizmat thinks that is a bug, it should just be "1", not a pair
<masak> lizmat++ # finding all these nice corner cases
<masak> lizmat: want me to submit the p => 0 one?
<lizmat> masak: please
* masak submits lizmat's rakudobug

Usually, just accessing a hash yields "1" in the above case. The :p
parameter says "give me the pair", and so passing in :p (as a named
parameter or an adverb, same thing) should indeed give "'a' => '1'".
But here lizmat is passing the named parameter with the value 0 (one
of the falsy values in Perl 6), which should again turn it off. (Use
case: passing in a variable which may be truthy or falsy.)

Carl Mäsak via RT

unread,
May 13, 2013, 2:25:51 PM5/13/13
to perl6-c...@perl.org
<lizmat> actually, the :p(0) also applies to :delete and :exists
<lizmat> rn: my %a; %a<a>=1; say %a<a>:delete(0); say %a
<camelia> rakudo 2a04f2: OUTPUT«1␤().hash␤»
<camelia> ..niecza v24-50-gba63d9a: OUTPUT«1␤{}␤»
<jnthn> lizmat: Correct.
* masak adds that to the ticket

Christian Bartolomaeus via RT

unread,
Jan 4, 2015, 11:00:03 AM1/4/15
to perl6-c...@perl.org
There have been some relevant changes since this ticket was created:

1 postcircumfix:<{ }> is a sub now.

2 There was a change to the design documents and according to S02 the adverbial forms :p, :kv, :k, :v "weed out non-existing entries if the adverb is true; if not, they leave them in, just as an ordinary slice would" (cmp. https://github.com/perl6/specs/commit/fd94c28225).

Taking these changes into account, now the mentioned commands run as expected. First the :p(0) stuff:

$ perl6 -e 'my %h; %h<a>=1; say %h<a>:p'
"a" => 1

$ perl6 -e 'my %h; %h<a>=1; say %h<a>:p(0)' ## same result since key "a" exists
"a" => 1

$ perl6 -e 'my %h; %h<a>=1; say %h<a>:!p' ## same thing
"a" => 1

$ perl6 -e 'my %h; %h<a>=1; say %h<b>:p' ## key "b" does not exist

$ perl6 -e 'my %h; %h<a>=1; say %h<b>:p(0)' ## pair not weeded out
"b" => Any

$ perl6 -e 'my %h; %h<a>=1; say %h<b>:!p' ## same thing
"b" => Any

The adverbs :delete and :exists also work as designed:

$ perl6 -e 'my %h; %h<a>=1; say %h<a>:delete; say %h'
1


$ perl6 -e 'my %h; %h<a>=1; say %h<a>:delete(0); say %h'
1
"a" => 1

$ perl6 -e 'my %h; %h<a>=1; say %h<a>:exists'
True

$ perl6 -e 'my %h; %h<a>=1; say %h<a>:exists(0)'
False

For :p(0) I added tests to S32-hash/pairs.t with commit https://github.com/perl6/roast/commit/a543b07ab4

For :delete(0) and :exists(0) there are passing tests in S32-hash/delete-adverb.t and S32-exists-adverb.t, respectively.

I'm closing this ticket now.
0 new messages