* Elizabeth Mattijsen <l...@dijkmat.nl> [2015-09-26 13:20]:
> The flattening will not be done if more than one argument is specified:
>
> $ 6 'my %h = a => 42, b => 666; my @a = %h,%h; dd @a'
> Array @a = [{:a(42), :b(666)}, {:a(42), :b(666)}]
>
>
> This is the same behaviour as with for:
>
> $ 6 'my %h = a => 42, b => 666; dd $_ for %h'
> :a(42)
> :b(666)
>
> $ 6 'my %h = a => 42, b => 666; dd $_ for %h,%h'
> Hash %h = {:a(42), :b(666)}
> Hash %h = {:a(42), :b(666)}
>
>
> It’s the same rule throughout  :-)

Yes, but adding a trailing comma to convert a lone item to an element in
a one-element list, causing the flattening to apply to the list instead
of the item, thus avoiding the flattening of that item as a side effect
of sorts… is just way too meta for my taste, at least for everyday parts
of the language.

> There is: you just need to itemize the hash, e.g. by prefixing it with $
>
> $ 6 'my %h = a => 42, b => 666; my @a = $%h; dd @a'
> Array @a = [{:a(42), :b(666)},]
>
> This is the one argument rule at work.

Aha! Much better. Explicit. “Don’t subject %h to flattening.”

No need to combine two other unrelated rules to bend around invoking the
undesired rule; just directly saying not to invoke it.

Now of course I must ask – is there an opposite also? I.e. when writing
a list, is there a way I can say “do flatten this item?” Or put in other
words, what goes in place of XXX in the following to make it real?

    $ 6 'my %h = a => 42, b => 666; dd $_ for %h,XXX'
    Hash %h = {:a(42), :b(666)}
    :a(42)
    :b(666)

Regards,
-- 
Aristotle Pagaltzis // <http://plasmasturm.org/>

Reply via email to