YAP6 Operator: The Pair Constructor
by Adriano Ferreira
Another article of the series "Yet Another Perl 6 Operator"
'=>' is no longer just a "fancy comma". In Perl 6, it now constructs a
Pair object that can, among other things, be used to pass named arguments to functions.
my $pair = (one => 1);
$pair.isa(Pair) # Bool::True
$pair.key # 'one'
$pair.value # 1
You have indirectly introduced me to a new concept that I was not aware of in perl6. "Item Context" sounds like a smart version of scalar context. You placed a list as a key in your pair, but instead of it turning into scalar context (and becoming a "3") it maintained it's state as a list.
Perl 6 still has scalar, list and void contexts. It adds some specialized scalar contexts like boolean, string, numeric, which Perl 5 already has internally (but maybe not that structured as in the new language) and which could be guessed by the overloaded context operators like
|You have $kv and $kv to get at individual elements of your @kv array, but in Perl6 shouldn't that read @kv and @kv?|