我在试验在Perl 6 REPL上定义运算符时遇到了问题,并注意到它们确实有效,但只有在它们被定义的同一行上使用时才会有效.为什么会这样?
> sub postfix:<!>(Int $x where { $x >= 0 }) { [*] 1..$x }; 6!;
720
> 6!;
===SORRY!=== Error while compiling:
Negation metaoperator not followed by valid infix
------> 6!?;
expecting any of:
infix
infix stopper
Run Code Online (Sandbox Code Playgroud) operators user-defined-functions perl6 read-eval-print-loop raku
I wanted to generate regex from an existing list of values, but when I attempted to use a capture within it, the capture was not present in the match. Is it not possible to have a capture using interpolation, or am I doing something wrong?
my @keys = <foo bar baz>;
my $test-pattern = @keys.map({ "<$_>" }).join(' || ');
grammar Demo1 {
token TOP {
[
|| <foo>
|| <bar>
|| <baz>
] ** 1..* % \s+
}
token foo …Run Code Online (Sandbox Code Playgroud) 除了在其中声明了签名的块之外,所有块均具有相同的标识值,并声称无论出现在何处都在第1行声明。有人能解释为什么会这样吗?
say ?Let's look at some blocks…?;
if True {
&?BLOCK.say;
}
while True {
&?BLOCK.say;
last;
}
loop {
&?BLOCK.say;
last;
}
if True -> | {
?I'm different!?.say;
&?BLOCK.say;
}
when ?True {
&?BLOCK.say;
}
Run Code Online (Sandbox Code Playgroud) 我希望脚本运行从模块导出的子例程,而导出的子例程将在脚本中作为MAIN运行。该子例程执行我想要的所有操作,除了它返回结果而不是打印结果。
RUN-MAIN 似乎可以达到我的目标,但是我不确定如何获取例程的返回值。
有什么方法可以捕获要打印的RUN-MAIN例程的输出?RUN-MAIN是否适合这种事情?