bri*_*foy 9 operator-precedence perl6 raku
say <a b c>[1];
Run Code Online (Sandbox Code Playgroud)
我认为相同的优先级适用于所有引用运算符.这有效:
my $string = '5+8i';
my $number = <<$string>>;
say $number;
Run Code Online (Sandbox Code Playgroud)
这会插入$string并创建allomorphes(在本例中为ComplexStr):
(5+8i)
Run Code Online (Sandbox Code Playgroud)
但是,如果我尝试将其编入索引,就像文档中的示例一样,它不会编译:
my $string = '5+8i';
my $number = <<$string>>[0];
say $number;
Run Code Online (Sandbox Code Playgroud)
我不太确定Perl 6在这里发生了什么.也许它认为这是一个超级高手:
===SORRY!=== Error while compiling ...
Cannot use variable $number in declaration to initialize itself
at /Users/brian/Desktop/scratch.pl:6
------> say $?number;
expecting any of:
statement end
statement modifier
statement modifier loop
term
Run Code Online (Sandbox Code Playgroud)
我可以跳过变量:
my $string = '5+8i';
say <<$string>>[0];
Run Code Online (Sandbox Code Playgroud)
但这是一个不同的错误,无法找到收尾报价:
===SORRY!=== Error while compiling ...
Unable to parse expression in shell-quote words; couldn't find final '>>'
at /Users/brian/Desktop/scratch.pl:8
------> <BOL>?<EOL>
expecting any of:
statement end
statement modifier
statement modifier loop
Run Code Online (Sandbox Code Playgroud)
我认为这保证了rakudobug电子邮件.我认为解析器在尝试将其解释为hyper(又名>>.method)时感到困惑.以下解决方法似乎证实了这一点:
my $string = '5+8i';
my $number = <<$string >>[0]; # note space before >>
say $number;
Run Code Online (Sandbox Code Playgroud)
为了满足你的强迫症,你可能还要先放一个空格$string.
是的,在Perl 6中,空格并非毫无意义.
Jonathan回答了RT#131695的答案.
这>>[]是一个用于索引列表的后缀运算符,因此它会尝试使用它.这是预期的行为.很公平,虽然我认为解析器对于常规代码猴来说有点太聪明了.