In general, it needs to be improved.
https://github.com/perl6/doc/issues/2167
Please add to that issue or open another one to comment this specific fact.
Cheers
JJ
I should mention something less obvious as well: a declaration both
manipulates symbols known to the compiler, and usually causes allocation of
storage at runtime; and for classes, composition has runtime components.
Among other things that must be split between compile-time and runtime. So
it's no
Thanks Brandon for your answer. Yes, I agree that it makes sense that
declarations (and initializations) outside any sub should run before the
MAIN sub.
And I agree that we should probably avoid combining a MAIN sub with
non-declaring code. (And, as I said, I've never hit the case before because
> On 19 Jul 2018, at 23:31, Laurent Rosenfeld via perl6-users
> wrote:
> I was expecting the MAIN message to be printed first.
>
> Did I miss something? Is my understanding wrong? I'd never seen that, but I
> guess all my scripts using MAIN had all the code in subs called from MAIN. So
> maybe
The MAIN sub executes after the mainline.
After all should MAIN be called before or after do-it('2') in the following?
sub do-it(Str $string) {
say $string;
}
do-it("1");
multi sub MAIN() {
say "This is MAIN so this should print after the mainline";
}
do-it
Consider that "declarations" are actually executable code. They have
compile-time meaning, but many also have runtime meaning. This is most
obvious when it's a variable with an initializer: the initialization is at
runtime, not compile time. Which means MAIN has to run after all such, or
variables