|Date:||Tue, 5 Jan 2016 08:42:11 +0100|
|From:||Tobias Leich <email [...] froggs.de>|
|To:||rakudobug [...] perl.org|
|Subject:||[FEATURE] make :%hash<key> a pair constructor|
For a while we can create Pairs from named captures of match variables: m: my %hash = key => 42; say (:$<key>) rakudo-moar ac4f9f: OUTPUT«key => Nil␤» Sadly, this does not even parse: m: my %hash = key => 42; say (:$/<key>) rakudo-moar ac4f9f: OUTPUT«===SORRY!=== Error while compiling /tmp/3GMq24eXRj␤Bogus statement␤at /tmp/3GMq24eXRj:1␤------> my %hash = key => 42; say (:$⏏/<key>)␤ expecting any of:␤ colon pair␤» Nor does this create a Pair: m: my %hash = key => 42; say (:%hash<key>) rakudo-moar ac4f9f: OUTPUT«(Mu)␤» So I vote for all shown statements to create a Pair of key => Nil or key => Any respectively. Funnily, Arrays behave differently when used with colonpair syntax: m: my @array = 42, 43; say (:@array) rakudo-moar ac4f9f: OUTPUT«array => [42 43]␤» Which is also wrong, IMO. This case should either produce 0 => 42, or array => 42. If we go for the latter then the shown Hashes should also be treated as subscripts, and produce hash => 42, if the variable is not anonymous like in $/<key> or $<key>. This would allow %hash<key foo>, but then again $<key foo> and $/<key Show quoted text
foo> need to parsefail.