While reading and trying signature smartmatching I run into something strange.
Executing the following smartmaching signature pairs:
my @sigs = :($a, $b), :($a, @b), :($a, %b);
my @signatures_to_check = :($, $), :($, @), :($, %);
my $c = 0;
for @sigs -> $sig {
for @signatures_to_check -> $s {
$c++;
if $sig ~~ $s {
say " [ $c ] " ~ $sig.gist ~ ' match ' ~ $s.gist;
next;
}
say " [ $c ] " ~ $sig.gist ~ ' do NOT match ' ~ $s.gist;
}
say "\n" ~ '#' x 40 ~ "\n";
}
I've got the following results:
[ 1 ] ($a, $b) match ($, $)
[ 2 ] ($a, $b) do NOT match ($, @)
[ 3 ] ($a, $b) do NOT match ($, %)
########################################
[ 4 ] ($a, @b) match ($, $)
[ 5 ] ($a, @b) match ($, @)
[ 6 ] ($a, @b) do NOT match ($, %)
########################################
[ 7 ] ($a, %b) match ($, $)
[ 8 ] ($a, %b) do NOT match ($, @)
[ 9 ] ($a, %b) match ($, %)
I've tried explaining myself cases [ 4 ] and [ 7 ] but I've failed!
Can somebody explain it to me?
How many things is a value that does the Positional
role? Or one that does the Associative
role?
The hint is in "a value that does..." and "one that does...". It's a single thing.
So, yes, an given Array
or Hash
has zero, one, two, or more elements. But it is, as itself, a single thing.
$
indicates a scalar symbol or value. What is the constraint on a scalar symbol or value? It is that it binds to a single thing at a time (even if that thing itself can contain multiple elements).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With