7

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 { ... };
brian d foy
  • 129,424
  • 31
  • 207
  • 592

1 Answers1

7

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.

Christoph
  • 164,997
  • 36
  • 182
  • 240
  • Well, the design might be described in those docs, but I wouldn't have thought that it was connected to what was going on in Int.pm. Thanks, – brian d foy Jun 14 '17 at 01:05