On Mon, 03 Jul 2017 05:46:46 -0700, comdog wrote:
> It seems that term precedence with << >> gets confused.
> 
The << >> quoting construct interpolates. The rule for interpolation of method 
calls, indexing, etc. after a scalar is that there may be one, but it may only 
end with a ], ), } or >.

> {
> my $number = <<$string>>[0];

When the variable is encountered inside of the interpolating quoting construct, 
which is being parsed by the quoting parser, it calls back into the Perl 6 main 
language parser. This parses a variable and optionally a postfix. The >>[0] is 
a valid postfix, where >> is the hyper-operator and [0] is the indexer. 
Therefore the $string>>[0] is taken as the thing to interpolate. It then hands 
back control to the quoting parser.

> put "Type: " ~ $number;
> #`(
> ===SORRY!=== Error while compiling ...
> Cannot use variable $number in declaration to initialize itself
> ------>     put "Type: " ~ $⏏number;

This is complaining that $number was used before its declaration was complete, 
which is indeed the case because at we are still inside of the quoting 
construct.

I can see the potential for a human reader to be confused, but the Perl 6 
parser is not in the least bit confused. There isn't any question as to what 
will parse the >>: if the main language parser understands it and wants it, 
then it gets it, because the quoting parser doesn't get a say again until the 
main language parser has done its bit. This is the same reason that you can do 
stuff like:

say "Foos: @foo.join("bar")"

And there isn't a bit of confusion so far as Perl 6 is concerned that the inner 
" is opening a new string, not closing the one we were already in. Granted it's 
maybe kinder to the reader to write it with single quotes inside of the string. 
But nestings of main language => quote parser => main language => quote parser 
will Just Work, each eating as much as it understands (or until seeing its 
terminator) before giving up control.

/jnthn

Reply via email to