Ralph Mellor wrote:
> Joseph Brenner wrote:
>
> > Before I get started here, a small point about defining hashes.
> > There are various ways that work:
> >
> >my %h1 = ( 'ha' => 1, 'ho' => 2, 'hum' => 3 );
> >my %h2 = ( ha => 1, ho => 2, hum => 3 );
> >my %h3 = ha => 1, ho =>
You've gotten a pile of great answers. :)
I'll add another to the pile, but omit explanation.
say % = ["foo" => "bar"], "baz" => 42; # {foo bar => baz => 42}
say % = ["foo" => "bar"]; # {foo => bar}
say % = ["foo" => "bar"],; # Odd number ... Only saw: $[:foo("bar")
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(
> On Apr 20, 2021, at 12:39 AM, 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 =
A Hash either takes some number of pairs
my %h = a => 1, b => 2;
or an even number of elements, which become key value pairs
my %h = 'a', 1, 'b', 2;
`eager` returns an eager Sequence/List etc
(eager a => 1).raku # (:a(1),)
A Sequence/List is itself a thing. Which means that it can
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 { tak