我的班级和我们在 Raku(perl6) 中的班级有什么区别? [英] What is the difference between my class and our class in Raku(perl6)?

查看:46
本文介绍了我的班级和我们在 Raku(perl6) 中的班级有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了规范,但我仍然对 my class[our] class 有何不同感到困惑.有何区别以及何时使用?

I've read the spec but I'm still confused how my class differs from [our] class. What are differences and when to use which?

推荐答案

与变量一样,my 在词法上绑定一个名称,而 our 在周围创建一个条目包.

As with variables, my binds a name lexically, whereas our additionally creates an entry in the surrounding package.

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 来使这些本地符号可用于导入代码.

Use my for classes internal to your module. You can of course still make such local symbols available to importing code by marking them is export.

这篇关于我的班级和我们在 Raku(perl6) 中的班级有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆