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

KeyBag accepts non-UInt values in Rakudo #3115

Closed
p6rt opened this issue Apr 26, 2013 · 11 comments
Closed

KeyBag accepts non-UInt values in Rakudo #3115

p6rt opened this issue Apr 26, 2013 · 11 comments

Comments

@p6rt
Copy link

p6rt commented Apr 26, 2013

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

Searchable as RT117773$

@p6rt
Copy link
Author

p6rt commented Apr 26, 2013

From @masak

<lizmat> more worringly​:
<lizmat> rn​: say KeyBag.new( (a=>"b") )<a>
<camelia> rakudo 71ea14, niecza v24-37-gf9c8fc2​: OUTPUT«b␤»
<lizmat> but but, shouldn't a keybag only contain uints as values
<masak> yes.
<lizmat> and complain about "b" being passed as a value?
<masak> yes.
* masak submits rakudobug

The spec says KeyBag defaults to UInt values.

<lizmat> "A C<KeyHash> represents a mutable set of values, represented
as the keys
<lizmat> of a C<Hash>. When asked to behave as a list it ignores its values
<lizmat> and returns only C<.keys>. C<KeySet> and C<KeyBag> are derived from
<lizmat> this type, but constrain their values to be C<Bool> and C<UInt>,
<lizmat> respectively."

@p6rt
Copy link
Author

p6rt commented Oct 15, 2014

From @usev6

This has changed. The former KeyBag is a BagHash now and the code snippet no longer generates a key "a" with a value "b". Instead it generates a key of type Pair ("a" => "b") with the corresponding value 1​:

$ perl6-m -e 'my $a = BagHash.new( (a=>"b") ); for $a.kv -> $key, $val { say $key, " isa ", $key.WHAT; say $val }'
"a" => "b" isa (Pair)
1

If I omit the parens around a=>"b" I get an empty BagHash​:

$ perl6-m -e 'my $a = BagHash.new( a=>"b" ); say $a.perl'
().BagHash

That looks reasonable to me. Is the ticket closable with tests?

1 similar comment
@p6rt
Copy link
Author

p6rt commented Oct 15, 2014

From @usev6

This has changed. The former KeyBag is a BagHash now and the code snippet no longer generates a key "a" with a value "b". Instead it generates a key of type Pair ("a" => "b") with the corresponding value 1​:

$ perl6-m -e 'my $a = BagHash.new( (a=>"b") ); for $a.kv -> $key, $val { say $key, " isa ", $key.WHAT; say $val }'
"a" => "b" isa (Pair)
1

If I omit the parens around a=>"b" I get an empty BagHash​:

$ perl6-m -e 'my $a = BagHash.new( a=>"b" ); say $a.perl'
().BagHash

That looks reasonable to me. Is the ticket closable with tests?

@p6rt
Copy link
Author

p6rt commented Oct 15, 2014

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

@p6rt
Copy link
Author

p6rt commented Oct 15, 2014

From @masak

bartolin (>)​:

That looks reasonable to me. Is the ticket closable with tests?

Yes, I think so.

@p6rt
Copy link
Author

p6rt commented Oct 15, 2014

From @usev6

I added a test for the first example to S02-types/baghash.t with the following commit​: Raku/roast@502f2ca59d

After staring at it for a while I'm no longer convinced that the following should result in an empty BagHash​:

$ perl6-m -e 'my $a = BagHash.new( a=>"b" ); say $a.perl'
().BagHash

Shouldn't that Hash get a Pair as it's first key as well? Compare the output with the a quoted.

$ perl6-m -e 'my $a = BagHash.new( "a"=>"b" ); for $a.kv -> $key, $val { say $key, " isa ", $key.WHAT; say $val }'
"a" => "b" isa (Pair)
1

For the time being I'll leave the ticket open.

1 similar comment
@p6rt
Copy link
Author

p6rt commented Oct 15, 2014

From @usev6

I added a test for the first example to S02-types/baghash.t with the following commit​: Raku/roast@502f2ca59d

After staring at it for a while I'm no longer convinced that the following should result in an empty BagHash​:

$ perl6-m -e 'my $a = BagHash.new( a=>"b" ); say $a.perl'
().BagHash

Shouldn't that Hash get a Pair as it's first key as well? Compare the output with the a quoted.

$ perl6-m -e 'my $a = BagHash.new( "a"=>"b" ); for $a.kv -> $key, $val { say $key, " isa ", $key.WHAT; say $val }'
"a" => "b" isa (Pair)
1

For the time being I'll leave the ticket open.

@p6rt
Copy link
Author

p6rt commented Oct 15, 2014

From @usev6

FROGGS explained on #perl6 why the empty BagHash is correct​:

< FROGGS> bartolin​: the bare a will result in a named argument, where the quoted "a" will construct a pair and pass that
< FROGGS> bartolin​: and methods (like .new in this case) happily eat named (optional by default) arguments, which is to spec
< bartolin> FROGGS​: thanks for explaining
< bartolin> FROGGS​: do you think we need a test for that case (a happily eaten named argument)? I tend to close the ticket without a further test (but with adding this explanation)
< FROGGS> bartolin​: yes, this behaviour (aka "interface consistency") shall be tested

I'll add a second test to S02-types/baghash.t and close this ticket afterwards.

1 similar comment
@p6rt
Copy link
Author

p6rt commented Oct 15, 2014

From @usev6

FROGGS explained on #perl6 why the empty BagHash is correct​:

< FROGGS> bartolin​: the bare a will result in a named argument, where the quoted "a" will construct a pair and pass that
< FROGGS> bartolin​: and methods (like .new in this case) happily eat named (optional by default) arguments, which is to spec
< bartolin> FROGGS​: thanks for explaining
< bartolin> FROGGS​: do you think we need a test for that case (a happily eaten named argument)? I tend to close the ticket without a further test (but with adding this explanation)
< FROGGS> bartolin​: yes, this behaviour (aka "interface consistency") shall be tested

I'll add a second test to S02-types/baghash.t and close this ticket afterwards.

@p6rt
Copy link
Author

p6rt commented Oct 15, 2014

From @usev6

Well, I hope that's it​: Raku/roast@9186415c7c

@p6rt
Copy link
Author

p6rt commented Oct 15, 2014

@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