Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

globals in !UNIT_START set up too late, or statements executed too early #697

Closed
p6rt opened this issue Feb 14, 2009 · 6 comments
Closed

Comments

@p6rt
Copy link

p6rt commented Feb 14, 2009

Migrated from rt.perl.org#63226 (status was 'resolved')

Searchable as RT63226$

@p6rt
Copy link
Author

p6rt commented Feb 14, 2009

From @chrisdolan

If you include statements in the body of a package, class, etc.
declaration, those are executed at :load time which happens
before :main. So, globals like @​*ARGS which are set up in !
UNIT_START from :main are not yet established. All three of the
following examples should have the same results, but the middle one
is wrong. Either setup of globals needs to happen before :load, or
the statements in the package, class, etc. need to be moved out
of :load methods. I think the latter is better, since :load methods
are like BEGIN blocks.

../../parrot perl6.pbc -e 'say "(", @​*ARGS, ")";' f g h
(fgh)

../../parrot perl6.pbc -e 'package Foo { say "(", @​*ARGS, ")"; }' f g h
()

../../parrot perl6.pbc -e 'package Foo { sub run() { say "(", @​*ARGS,
")"; } }; Foo​::run()' f g h
(fgh)

@p6rt
Copy link
Author

p6rt commented Jul 28, 2010

From @coke

On Fri Feb 13 20​:46​:31 2009, chris@​chrisdolan.net wrote​:

If you include statements in the body of a package, class, etc.
declaration, those are executed at :load time which happens
before :main. So, globals like @​*ARGS which are set up in !
UNIT_START from :main are not yet established. All three of the
following examples should have the same results, but the middle one
is wrong. Either setup of globals needs to happen before :load, or
the statements in the package, class, etc. need to be moved out
of :load methods. I think the latter is better, since :load methods
are like BEGIN blocks.

../../parrot perl6.pbc -e 'say "(", @​*ARGS, ")";' f g h
(fgh)

../../parrot perl6.pbc -e 'package Foo { say "(", @​*ARGS, ")"; }' f g h
()

../../parrot perl6.pbc -e 'package Foo { sub run() { say "(", @​*ARGS,
")"; } }; Foo​::run()' f g h
(fgh)

... Now a /different/ two of these work​:

$ ./perl6 -e 'say "(", @​*ARGS, ")";' f g h
(fgh)
$ ./perl6 -e 'package Foo { say "(", @​*ARGS, ")"; }' f g h
(fgh)
$ ./perl6 -e 'package Foo { sub run() { say "(", @​*ARGS, ")"; } }; Foo​::run()' f g h
Can not find sub Foo​::run
  in main program body at line 1

--
Will "Coke" Coleda

@p6rt
Copy link
Author

p6rt commented Jul 28, 2010

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Jul 28, 2010

From @coke

On Tue Jul 27 18​:07​:28 2010, coke wrote​:

On Fri Feb 13 20​:46​:31 2009, chris@​chrisdolan.net wrote​:

If you include statements in the body of a package, class, etc.
declaration, those are executed at :load time which happens
before :main. So, globals like @​*ARGS which are set up in !
UNIT_START from :main are not yet established. All three of the
following examples should have the same results, but the middle one
is wrong. Either setup of globals needs to happen before :load, or
the statements in the package, class, etc. need to be moved out
of :load methods. I think the latter is better, since :load methods
are like BEGIN blocks.

../../parrot perl6.pbc -e 'say "(", @​*ARGS, ")";' f g h
(fgh)

../../parrot perl6.pbc -e 'package Foo { say "(", @​*ARGS, ")"; }' f
g h
()

../../parrot perl6.pbc -e 'package Foo { sub run() { say "(",
@​*ARGS,
")"; } }; Foo​::run()' f g h
(fgh)

... Now a /different/ two of these work​:

$ ./perl6 -e 'say "(", @​*ARGS, ")";' f g h
(fgh)
$ ./perl6 -e 'package Foo { say "(", @​*ARGS, ")"; }' f g h
(fgh)
$ ./perl6 -e 'package Foo { sub run() { say "(", @​*ARGS, ")"; } };
Foo​::run()' f g h
Can not find sub Foo​::run
in main program body at line 1

jnthn++ points out that this last failure is correct. This should be written​:

$ ./perl6 -e 'package Foo { our sub run() { say "(", @​*ARGS, ")"; } }; Foo​::run()' f g h
(fgh)

which works. Assigning to moritz for spectesting.

--
Will "Coke" Coleda

@p6rt
Copy link
Author

p6rt commented Sep 14, 2011

From @tadzik

On Tue Jul 27 18​:12​:24 2010, coke wrote​:

Assigning to moritz for spectesting.

Got some work of moritz's back. Test added in
Raku/roast@e42db46331

@p6rt
Copy link
Author

p6rt commented Sep 14, 2011

@jnthn - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant