类名在 之后的范围内可用EVALFILE,而文档可能另有说明。
EVALFILE 状态的文档:
Slurps 指定的文件并对其进行评估。在Blob 解码、范围、$lang 参数和 $check 参数方面的行为与EVAL相同。当 $check 不为 True 时,计算文件中最后一条语句产生的值。
EVAL 状态的文档:
由于词法作用域中的符号集在编译后是不可变的,因此EVAL 永远不能将符号引入周围的作用域。
我的输入文件是:
class SomeClass {
method a () { "In SomeClass method a"; };
}
sub some-routine () {
"Some routine";
}
Run Code Online (Sandbox Code Playgroud)
> my $f = EVALFILE("/tmp/eval-bug.raku");
&some-routine
> $f()
Some routine
> some-routine()
===SORRY!=== Error while compiling:
Undeclared routine:
some-routine used at line 1
Run Code Online (Sandbox Code Playgroud)
以上三个执行符合文档,但以下不符合:
> SomeClass.a()
In SomeClass method a
Run Code Online (Sandbox Code Playgroud)
那么符号仅表示例程名称而不是类名称吗?或者这是一个错误?
为什么不:=导出带有绑定的变量的值?
$ cat myModule.pm6
our $a is export = 42;
our $b is export := $a;
$ cat program.p6
use myModule;
say $a;
say $b;
$ perl6 program.p6
42
(Any) # Why?
Run Code Online (Sandbox Code Playgroud) 我已经阅读了规范,但我仍然很困惑my class与[our] class. 有什么区别以及何时使用哪个?