Barewords can be used at the left hand side of Pair declarations (this is not documented yet, I'm addressing this issue right now, but I want to get everything right). However, I have not found what is and what's not going to be considered a bareword key anywhere.
This seems to work
say (foo'bar-baz => 3); # OUTPUT: «foo'bar-baz => 3»
This does not
say (foo-3 => 3); # OUTPUT: «(exit code 1) ===SORRY!=== Error while compiling /tmp/jorTNuKH9VUndeclared routine: foo used at line 1»
So it apparently follows the same syntax as the ordinary identifiers. Is that correct? Am I missing something here?
There are no barewords in Perl 6 in the sense that they exist in Perl 5, and the term isn't used in Perl 6 at all.
There are two cases that we might call a "bare identifier":
\h*
), followed by the characters =>
. This takes the identifier on the left as a pair key, and the term parsed after the =>
as a pair value. This is an entirely syntactic decision; the existence of, for example, a sub or type with that identifier will not have any influence.These two cases are only related in the sense that they are both cases of term
s in the Perl 6 grammar, and that they both look to parse an identifier
, which follow the standard rules linked in the question. Which wins is determined by Longest Token Matching semantics; the restriction that there may only be horizontal whitespace between the identifier and =>
exists to make sure that the identifier, whitespace, and =>
will together be counted as the declarative prefix, and so case 1 will always win over case 2.
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