Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
p6rt opened this issue May 9, 2013 · 6 comments

Comments

@p6rt
Copy link

p6rt commented May 9, 2013

Migrated from rt.perl.org#117935 (status was 'resolved')

Searchable as RT117935$

@p6rt
Copy link
Author

p6rt commented May 9, 2013

From @masak

<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.)

@p6rt
Copy link
Author

p6rt commented May 13, 2013

From @masak

<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

@p6rt
Copy link
Author

p6rt commented May 13, 2013

@masak - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Jan 4, 2015

From @usev6

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. Raku/old-design-docs@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 Raku/roast@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.

1 similar comment
@p6rt
Copy link
Author

p6rt commented Jan 4, 2015

From @usev6

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. Raku/old-design-docs@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 Raku/roast@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.

@p6rt p6rt closed this as completed Jan 4, 2015
@p6rt
Copy link
Author

p6rt commented Jan 4, 2015

@usev6 - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant