为什么我不能在 "while" 上调用 "gist"? (Perl 6)
Why can't I call "gist" on "while"? (Perl 6)
我可以在 say
内置函数上调用 gist
方法:
&say.gist
sub say (| is raw) { #`(Sub|54790064) ... }
为什么我不能在 while
上呼叫 gist
?
&while.gist
===SORRY!=== Error while compiling <unknown file>
Undeclared routine:
while used at line 1
显然 while
不是 "routine" 但 say
是。但我认为 Perl 6 中的所有内置函数都是我们可以重新定义的函数。
I thought that all of the built-ins in Perl 6 were really functions that we could redefine.
while
不是例程或宏,而是语法的一部分,定义在Perl6's grammar.
如果你想重新定义它,你必须创造你自己的俚语,目前它涉及黑魔法。
出于某种原因我还没有弄清楚,它只有在模块中完成时才有效(否则,%*LANG
似乎没有定义)。
让我们调用模块 froop.pm6
:
use nqp;
sub EXPORT {
nqp::bindkey(%*LANG, 'MAIN', nqp::atkey(%*LANG, 'MAIN').^mixin(role {
rule statement_control:sym<while> {
[$<sym>=froop{
$/.hash<sym>.^mixin: role {
method Str { 'while' }
}
}|$<sym>=until]<.kok> {}
<xblock>
}
}));
once Map.new
}
这会将 while
关键字(在语句位置)替换为 froop
,例如
use froop;
my $i = 0;
froop $i < 5 { say $i++ }
我可以在 say
内置函数上调用 gist
方法:
&say.gist
sub say (| is raw) { #`(Sub|54790064) ... }
为什么我不能在 while
上呼叫 gist
?
&while.gist
===SORRY!=== Error while compiling <unknown file> Undeclared routine: while used at line 1
显然 while
不是 "routine" 但 say
是。但我认为 Perl 6 中的所有内置函数都是我们可以重新定义的函数。
I thought that all of the built-ins in Perl 6 were really functions that we could redefine.
while
不是例程或宏,而是语法的一部分,定义在Perl6's grammar.
如果你想重新定义它,你必须创造你自己的俚语,目前它涉及黑魔法。
出于某种原因我还没有弄清楚,它只有在模块中完成时才有效(否则,%*LANG
似乎没有定义)。
让我们调用模块 froop.pm6
:
use nqp;
sub EXPORT {
nqp::bindkey(%*LANG, 'MAIN', nqp::atkey(%*LANG, 'MAIN').^mixin(role {
rule statement_control:sym<while> {
[$<sym>=froop{
$/.hash<sym>.^mixin: role {
method Str { 'while' }
}
}|$<sym>=until]<.kok> {}
<xblock>
}
}));
once Map.new
}
这会将 while
关键字(在语句位置)替换为 froop
,例如
use froop;
my $i = 0;
froop $i < 5 { say $i++ }