The 'take' is creating a Pair, which is one thing, whilst when creating
a hash, you need two things: the key and the value.
The gather adds extra complexity by creating a list, which is also one
thing. But you could flatten the list into the list of things by using |.
So `my %h = gather { take eager "foo"=>1}` has only the `foo=>1` as the
first thing, which is the key, but nothing for the key to point to.
Your `my %h = gather { take eager "foo"=>1; take "bar"=>2;}` has two
things. The `foo=>1` is the key, and the `bar=>2` is the value. That's
what was being shown in the output, but with the implied parentheses it
is not easy to see at first. You got `{foo 1 => bar => 2}`, which is {
(foo=>1) => (bar=>2) }
(Note the before => the key is auto-quoted, so no need to use "foo"=>1.
Hope this helps.
On 20/04/2021 06:39, Norman Gaywood 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
--
Norman Gaywood, Computer Systems Officer
School of Science and Technology
University of New England
Armidale NSW 2351, Australia
ngayw...@une.edu.au <mailto:ngayw...@une.edu.au>
http://turing.une.edu.au/~ngaywood <http://turing.une.edu.au/~ngaywood>
Phone: +61 (0)2 6773 2412 Mobile: +61 (0)4 7862 0062
Please avoid sending me Word or Power Point attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
<http://www.gnu.org/philosophy/no-word-attachments.html>