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

Should Perl 6 run MAIN if the file is required? #5826

Open
p6rt opened this issue Nov 26, 2016 · 4 comments
Open

Should Perl 6 run MAIN if the file is required? #5826

p6rt opened this issue Nov 26, 2016 · 4 comments
Labels
RFC Request For Comments

Comments

@p6rt
Copy link

p6rt commented Nov 26, 2016

Migrated from rt.perl.org#130185 (status was 'open')

Searchable as RT130185$

@p6rt
Copy link
Author

p6rt commented Nov 26, 2016

From @briandfoy

Here's a short Perl 6 program that declare a `MAIN` subroutine. I
should only see output if I execute the program directly​:

$ cat main.pm6
sub MAIN { say "Called as a program!" }

And I see output when I execute the program directly​:

$ perl6 main.pm6
Called as a program!

If I load it as a module, I see no output​:

$ perl6 -I. -Mmain -e "say 'Hey'"
Hey

Same if I `use` it from inside the program, I see no output​:

$ perl6 -I. -e 'use main'

But, if I use `require`, I get output​:

$ perl6 -I. -e 'require <main.pm6>'
Called as a program!

[Synopsis 06](http://design.perl6.org/S06.html#Declaring_a_MAIN_subroutine)
literally says _the compilation unit was directly invoked rather than
by being required_. Is there something else going on because `require`
works at runtime (although S06 doesn't exclude that)?

I get the same behaviour with Rakudo Star 2016.07 and 2016.10.

I realize that the Synopses are dated. Absent anything else noting
divergence from the design docs or the lack of documentation of the
feature in the docs, I think most people are going to assume the
original intent.

MAIN is very lightly documented in Language/functions.pod6. The
verbiage "relevant phasers" should be expanded so a reader knows whats
relevant. I didn't find anything in the docs that said MAIN shouldn't
run in some circumstances and not others. The docs seem to say that it
will always run, but that's not true either.

Also asked on Stackoverflow​: http://stackoverflow.com/q/40778852/2766176

@p6rt
Copy link
Author

p6rt commented Nov 27, 2016

From @lizmat

FWIW, this indeed feels as a bug to me

On 27 Nov 2016, at 00​:51, brian d foy (via RT) <perl6-bugs-followup@​perl.org> wrote​:

# New Ticket Created by "brian d foy"
# Please include the string​: [perl #​130185]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=130185 >

Here's a short Perl 6 program that declare a `MAIN` subroutine. I
should only see output if I execute the program directly​:

$ cat main.pm6
sub MAIN { say "Called as a program!" }

And I see output when I execute the program directly​:

$ perl6 main.pm6
Called as a program!

If I load it as a module, I see no output​:

$ perl6 -I. -Mmain -e "say 'Hey'"
Hey

Same if I `use` it from inside the program, I see no output​:

$ perl6 -I. -e 'use main'

But, if I use `require`, I get output​:

$ perl6 -I. -e 'require <main.pm6>'
Called as a program!

[Synopsis 06](http://design.perl6.org/S06.html#Declaring_a_MAIN_subroutine)
literally says _the compilation unit was directly invoked rather than
by being required_. Is there something else going on because `require`
works at runtime (although S06 doesn't exclude that)?

I get the same behaviour with Rakudo Star 2016.07 and 2016.10.

I realize that the Synopses are dated. Absent anything else noting
divergence from the design docs or the lack of documentation of the
feature in the docs, I think most people are going to assume the
original intent.

MAIN is very lightly documented in Language/functions.pod6. The
verbiage "relevant phasers" should be expanded so a reader knows whats
relevant. I didn't find anything in the docs that said MAIN shouldn't
run in some circumstances and not others. The docs seem to say that it
will always run, but that's not true either.

Also asked on Stackoverflow​: http://stackoverflow.com/q/40778852/2766176

@p6rt
Copy link
Author

p6rt commented Nov 27, 2016

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

@p6rt
Copy link
Author

p6rt commented Nov 30, 2016

From @jnthn

On Sun, 27 Nov 2016 02​:39​:29 -0800, elizabeth wrote​:

FWIW, this indeed feels as a bug to me

To me also. We may also want to consider what happens with `EVAL` and `EVALFILE`, while we get this nailed down.

/jnthn

@p6rt p6rt added the RFC Request For Comments label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFC Request For Comments
Projects
None yet
Development

No branches or pull requests

1 participant