I can get this to work (in the Raku REPL):

> my %h = gather { take("foo" => 1).eager}
{foo => 1}
>

If I imagine that ":eager" is an adverb modifying take(), it fails:

> my %h = gather { take(:eager) "foo" => 1}
===SORRY!=== Error while compiling:
Two terms in a row
------> my %h = gather { take(:eager) "foo" => 1}
    expecting any of:
        infix
        infix stopper
        statement end
        statement modifier
        statement modifier loop
> my %h = gather { take(:eager, "foo" => 1) }
Unexpected named argument 'eager' passed
  in block <unit> at <unknown file> line 1

If I interpose ".eager" between "take()" and its arguments, it still fails:

> my %h = gather { take.eager: "foo" => 1}
take without parameters doesn't make sense
  in block <unit> at <unknown file> line 1

> $*VM
moar (2020.10)
>

HTH, Bill.


On Tue, Apr 20, 2021 at 8:00 AM Bruce Gray <robertbrucegr...@gmail.com> wrote:
>
>
> > 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