To the best of my knowledge:

On Thu, 18 May 2017 03:52:42 -0700, elizabeth wrote:
> Should this work? If not, why not?

No, because the symbol is lexical to the compunit. It's the same as how you 
won't be able
to access subs or `my` constants or variables, unless you make them `our` or 
export them.

> What would be the way to inherit from lexical classes in other compunits?

One way would be to export them:

./A.pm6:
my class A is export {}

./B.pm6:
my class B {
    use A;
    also is A;
}
say B.^mro;

$ ./perl6 -I. -MB -e ''
((B) (A) (Any) (Mu))


You can also use export sub:
./A.pm6:
sub EXPORT {
    Map.new: 'A' => my class A {}
}

Or (I'm unsure what the end goal here is), take a special export arg and only 
export the class if it's present:

./A.pm6:
sub EXPORT ($secret-password?) {
    Map.new: (
        'A' => my class A {
        } if $secret-password ~~ 42
    )
}

./B.pm6:
my class B {
    use A;
    also is A;
}
say B.^mro;

$ ./perl6 -I. -MB -e ''
===SORRY!=== Error while compiling /home/zoffix/CPANPRC/rakudo/B.pm6 (B)
'B' cannot inherit from 'A' because it is unknown.
at /home/zoffix/CPANPRC/rakudo/B.pm6 (B):3


Now change ./B.pm6 to:
my class B {
    use A 42;
    also is A;
}
say B.^mro;

$ ./perl6 -I. -MB -e ''
((B) (A) (Any) (Mu))

Reply via email to