raku - 我的类(class)和我们在 Raku(perl6) 中的类(class)有什么区别?

标签 raku

我已经阅读了规范,但我仍然很困惑 my class[our] class 有何不同。有什么区别以及何时使用哪个?

最佳答案

与变量一样,my 在词法上绑定(bind)一个名称,而 our 在周围的包中另外创建一个条目。

module M {
    our class Foo {}
    class Bar {} # same as above, really
    my class Baz {}
}

say M::Foo; # ok
say M::Bar; # still ok
say M::Baz; # BOOM!

my 用于模块内部的类。当然,您仍然可以通过标记 is export 来使这些本地符号可用于导入代码。

关于raku - 我的类(class)和我们在 Raku(perl6) 中的类(class)有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33788788/

相关文章:

perl - 附加:from<perl5> suffix to the module name in a 'use' statement in Perl 6?的目的是什么

multithreading - 在 Perl 6 中运行自馈 channel

raku - Perl 6 : what's the best way to check if an element is in a list?

grammar - .parse anchor 还是 :sigspace first in a Perl 6 rule?

raku - 在 Perl 6 中使用循环组合正则表达式

unicode - 为什么 .ords 与 .chars 不一致?

read-eval-print-loop - Perl6 REPL 用法

raku - <class> 类型的调用者没有这样的方法 <name>

operators - Raku 混淆后缀 ,= 操作符行为

raku - Perl6 日志方法返回 Num 而不是 Rat