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

{} syntax doesn't make hash with %*var inside #2903

Closed
p6rt opened this issue Sep 19, 2012 · 6 comments
Closed

{} syntax doesn't make hash with %*var inside #2903

p6rt opened this issue Sep 19, 2012 · 6 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Sep 19, 2012

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

Searchable as RT114966$

@p6rt
Copy link
Author

p6rt commented Sep 19, 2012

From sirrobert@gmail.com

(distilled from log)

11​:06 < sirrobert> r​: my @​arr; @​arr.push(%(a => 1, b => 2)); say @​arr.perl;
11​:06 <+p6eval> rakudo 097361​: OUTPUT«Array.new("a" => 1, "b" => 2)␤»
11​:06 < sirrobert> I expected that to give me an array with one element
that was a hash
11​:06 < sirrobert> what did I do wrong?
11​:07 < sirrobert> or maybe​: how should I think about that?
11​:07 < masak> push expects a list of things. if it finds a hash, it
listifies the hash.
11​:07 < sirrobert> ok, how do I get it not to listify things?
11​:08 < sirrobert> if I want an array of hashes
11​:08 < masak> r​: my @​a; @​a.push({ a => 1, b => 2}); say @​a.perl
11​:08 <+p6eval> rakudo 097361​: OUTPUT«Array.new({"a" => 1, "b" => 2})␤»
11​:08 < sirrobert> ok
11​:08 < sirrobert> so what I really have is​:
11​:09 < sirrobert> r​: my @​a; @​a.push(%((1,2,3) Z=> (<a b c>))); say @​a.perl;
11​:09 <+p6eval> rakudo 097361​: OUTPUT«Array.new("1" => "a", "2" => "b", "3"
=> "c")␤»
11​:09 < sirrobert> is the "right" solution here to create the hash
separately? but it
  still gets expanded...
11​:09 < sirrobert> I think
11​:09 < masak> yeah.
11​:09 < masak> r​: my @​a; my %h = (1,2,3) Z=> (<a b c>); @​a.push(%h); say
@​a.perl
11​:09 <+p6eval> rakudo 097361​: OUTPUT«Array.new("1" => "a", "2" => "b", "3"
=> "c")␤»
11​:09 < masak> indeed.
11​:09 < masak> r​: my @​a; my %h = (1,2,3) Z=> (<a b c>); @​a.push({%h}); say
@​a.perl
11​:10 <+p6eval> rakudo 097361​: OUTPUT«Array.new({"1" => "a", "2" => "b",
"3" => "c"})␤»
11​:10 < sirrobert> ohh.. weird
11​:10 < sirrobert> ok, I can live with that =)
11​:11 < pmichaud> r​: my @​a; @​a.push({ (1,2,3) Z <a b c> }); say @​a.perl
11​:11 <+p6eval> rakudo 097361​: OUTPUT«Array.new(Block.new())␤»
11​:11 < moritz> sirrobert​: what's weird about it?
11​:11 < sirrobert> the {%} seems redundant
11​:11 < moritz> well, the {} makes an hash-in-an-item
11​:11 < sirrobert> moritz​: a workaround for the listification magic of push
11​:11 < moritz> you can also say %h.item
11​:12 < sirrobert> ok, that's a good paradigm for me to adopt for it
11​:12 < sirrobert> I didn't previously have a concept of 'item'
11​:13 < sirrobert> huh... push({%...}) interprets it as a hash but push​:
{%...} interprets
  it as a block
11​:14 < moritz> that's weird
11​:14 < sirrobert> verifying now ...
11​:14 < moritz> r​: my @​h; @​h.push​: {%*ENV}; say @​h[0].WHAT
11​:14 <+p6eval> rakudo 097361​: OUTPUT«Block()␤»
11​:15 < moritz> r​: my @​h; @​h.push({%*ENV}); say @​h[0].WHAT
11​:15 <+p6eval> rakudo 097361​: OUTPUT«Block()␤»
11​:15 < moritz> sirrobert​: seems to be a block either way :(
11​:15 < moritz> r​: my %a; my @​h; @​h.push({%a}); say @​h[0].WHAT
11​:15 <+p6eval> rakudo 097361​: OUTPUT«Hash()␤»
11​:15 < moritz> r​: my %a; my @​h; @​h.push​: {%a}; say @​h[0].WHAT
11​:15 <+p6eval> rakudo 097361​: OUTPUT«Hash()␤»
11​:15 < moritz> erm, what?
11​:15 < sirrobert> moritz​: erm, indeed =)
11​:16 < moritz> %*ENV makes it a block, %a a hash?
11​:16 * moritz smeells a rakudobug
11​:18 < sirrobert> r​: my $h = {%(<a b>) Z=> (1,2)}; say $h.WHAT;
11​:18 <+p6eval> rakudo 097361​: OUTPUT«Block()␤»
11​:19 < masak> moritz​: that feels buggish, yes.
11​:19 < masak> moritz​: care to report it?
11​:19 < sirrobert> sure
11​:19 < sirrobert> if I copy/paste this discussion is that enough? I don't
quite know how
  to describe it.
11​:19 < moritz> yes, it's enough
11​:19 < sirrobert> ok, one sec

@p6rt
Copy link
Author

p6rt commented Sep 19, 2012

From @moritz

A bit more concise​:

19​:09 < moritz> r​: my %a; say {%a}.WHAT
19​:09 <+p6eval> rakudo 097361​: OUTPUT«Hash()␤»
19​:10 < moritz> r​: my %*a; say {%*a}.WHAT
19​:10 < p6eval> rakudo 097361​: OUTPUT«Block()␤»

@p6rt
Copy link
Author

p6rt commented Sep 19, 2012

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Aug 2, 2013

From @moritz

On Wed Sep 19 10​:12​:02 2012, moritz wrote​:

A bit more concise​:

19​:09 < moritz> r​: my %a; say {%a}.WHAT
19​:09 <+p6eval> rakudo 097361​: OUTPUT«Hash()␤»
19​:10 < moritz> r​: my %*a; say {%*a}.WHAT
19​:10 < p6eval> rakudo 097361​: OUTPUT«Block()␤»

And both should say "Hash".

@p6rt
Copy link
Author

p6rt commented May 1, 2015

From @jnthn

On Wed Sep 19 10​:12​:02 2012, moritz wrote​:

A bit more concise​:

19​:09 < moritz> r​: my %a; say {%a}.WHAT
19​:09 <+p6eval> rakudo 097361​: OUTPUT«Hash()␤»
19​:10 < moritz> r​: my %*a; say {%*a}.WHAT
19​:10 < p6eval> rakudo 097361​: OUTPUT«Block()␤»

Implemented this case, and added a test in S06-other/anon-hashes-vs-block.t.

@p6rt
Copy link
Author

p6rt commented May 1, 2015

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

@p6rt p6rt closed this as completed May 1, 2015
@p6rt p6rt added the Bug label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant