-
Notifications
You must be signed in to change notification settings - Fork 15
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
Implement MAIN #405
Comments
Yes, you can write convoluted code because of this, that looks like it's running out of order. But it's not something we're going to enforce either way. Just write clear code. |
As implementation started, I realized two things:
|
I just realized a thing: MAIN macro. At first I thought this was just a fanciful notion, but the more I think about it, the more consistent it seems. So now I think we have to do it that way, even pending the appearance of a motivating use case. Maybe through a different issue, though. |
One interesting consequence of #490 on The problem, though, is what we do when switching over types. I've always disliked what Perl 6 does here, even if it might be a necessary evil. I don't want |
Ooh, and all this should mean that the |
I haven't felt the need for it so far, but now that I'm picturing the module ecosystem of 007 modules, a
MAIN
function seems like it would pull its own weight.It would act as a kind of "am I being run directly (as opposed to being loaded as a module)" check, and a rather nice-looking one at that. Python has this pattern, but does it through magic variables, which actually looks ugly and surprisingly un-Pythonic. Anyway, it seems that modules often want this, a way to be run directly and basically act as a CLI tool as well.
It would also allow for a nice, clean way to accept command-line arguments. In the long run we might also want to have some kind of array with all the arguments in it, but this will do for a start.
I figure the semantics should be this: all of the mainline runs first, and then
MAIN
runs, if it contains aFunc
value. Note that all of the mainline runs, no matter where theMAIN
is defined. Doing it this way also allows patterns such as...in case we already had a (possibly exported) function already doing what we wanted
MAIN
to do. (Python would approve.)The text was updated successfully, but these errors were encountered: