Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are all of the classes in Rakudo's src/core/Int.pm declared with my?

Looking at the source for Int, I see that all of the classes are declared with my, which I would have thought would make them private and not available outside that file. But, they obviously are. Why do they need to be declared that way?

my class Rat { ... }
my class X::Numeric::DivideByZero { ... }
my class X::NYI::BigInt { ... }

my class Int { ... }
my subset UInt of Int where {not .defined or $_ >= 0};

my class Int does Real { # declared in BOOTSTRAP

I figure that BOOTSTRAP comment has something to do with it. In the Perl6/Metamodel/BOOTSTRAP.nqp there are lines like:

my stub Int metaclass Perl6::Metamodel::ClassHOW { ... };
like image 803
brian d foy Avatar asked Jun 12 '17 22:06

brian d foy


1 Answers

The files in Rakudo's src/core/ directory are not compiled as separate modules with their own private file-level scope, but concatenated into a single file such as gen/moar/CORE.setting during the build proceess.

Sematically, this 'setting' (known as 'prelude' in other languges) forms an outer lexical scope implicitly surrounding your program.

The design is described in S02: Pseudo-packages, and parts of that section have made it into the official documentation.

like image 145
Christoph Avatar answered Nov 15 '22 10:11

Christoph