> On Apr 20, 2021, at 12:39 AM, Norman Gaywood <ngayw...@une.edu.au> wrote:
> 
> Hi, I can't figure out why the last line here is failing.
> Version 2020.07
> 
> $ raku
> To exit type 'exit' or '^D'
> > my %h = gather { take "foo"=>1; take "bar"=>2;}
> {bar => 2, foo => 1}
> > my %h = gather { take "foo"=>1}
> {foo => 1}
> > my %h = gather { take eager "foo"=>1; take "bar"=>2;}
> {foo  1 => bar => 2}
> > my %h = gather { take eager "foo"=>1}
> Odd number of elements found where hash initializer expected:
> Only saw: $(:foo(1),)
>   in block <unit> at <unknown file> line 1
—snip—

Whenever I get that hash assignment 'Odd number of elements' error in Perl or 
Raku,
I gain clarity by replacing the hash with an array, and inspecting the array.

> my @a = gather { take       "foo"=>1; take "bar"=>2; }; say .raku ~ ' is a ' 
> ~ .WHAT.gist for @a;
        :foo(1) is a (Pair)
        :bar(2) is a (Pair)
> my @a = gather { take       "foo"=>1                 }; say .raku ~ ' is a ' 
> ~ .WHAT.gist for @a;
        :foo(1) is a (Pair)
> my @a = gather { take eager "foo"=>1; take "bar"=>2; }; say .raku ~ ' is a ' 
> ~ .WHAT.gist for @a;
        $(:foo(1),) is a (List)
        :bar(2) is a (Pair)
> my @a = gather { take eager "foo"=>1                 }; say .raku ~ ' is a ' 
> ~ .WHAT.gist for @a;
        $(:foo(1),) is a (List)

This does not address why `eager` is changing the pair constructor, 
but it simplifies future discussion, 
and also shows that while only #4 of the OP REPL samples was throwing the 
error, 
#3 is actually also not producing what was desired.

-- 
Hope this helps,
Bruce Gray (Util of PerlMonks)

Reply via email to