On Thu, 06 Apr 2017 13:46:00 -0700, [email protected] wrote:
> Code:
> my @a = <a b c>;
> my @b = <1 2 3>;
> my @c = @a, @b;
> say @c
>
> Result:
> [[a b c] [1 2 3]]
>
>
> So with arrays, nothing is flattened and you get an array with two
> elements. Makes sense.
>
> And if we want to get a different behavior, we can use slip:
>
> Code:
> my @a = <a b c>;
> my @b = <1 2 3>;
> my @c = |@a, |@b;
> say @c
>
> Result:
> [a b c 1 2 3]
>
>
> Everything is fine so far. Now, let's try the same thing with hashes:
>
> Code:
> my %a = <a b c d>;
> my %b = <1 2 3 4>;
> my %c = %a, %b;
> say %c
>
> Result:
> {1 => 2, 3 => 4, a => b, c => d}
>
>
> To me that looks like an inconsistency, I would have expected it to
> create a hash with one pair (%a => %b). In fact, both 「%c = %a, %b」
> and 「%c = |%a, |%b」 work exactly the same!
>
> The idea of %a => %b may seem weird, but it really isn't if you
> consider object hashes (my %c{Hash} = %a => %b; or even my %c{Hash} =
> $%a, $%b)
>
> Another thing to note is that this array behavior was changed during
> the GLR, but hashes remained the same. Perhaps that was an oversight.
The overwhelming majority of usecases would want merged hashes, not a hash
keyed on another hash.
Also, there is consistency with Pairs:
m: my %h = :2a, :3a; dd %h
<camelia> rakudo-moar 605e9e: OUTPUT: «Hash %h = {:a(3)}»
Why would `Hash, Hash` end up as keyed on a Hash, when `Pair, Pair` gets merged?
This parallel is much closer than the Array one, so I'd argue it overrules the
inconsistency with more distant types.