Gregor N. Purdy wrote:

Personally, I view Perl 6 as such a completely new language (although
still Perlish in spirit, it is very different in other respects), that
I would be perfectly happy to be required to start all my Perl 6
programs with "#!/usr/bin/perl6" instead of "#!/usr/bin/perl", just
the same as I'd start a Python program with "#!/usr/bin/python".

I second that. It should work, but maybe doesn't have to be required. Here's an idea how few different disambiguating methods (i.e. perl binary name, pragmas, command line switches and class-like keywords) could all work together in a fairly clear and consistent manner. It requires a little change of C<use VERSION> meaning in Perl 6 but only in a case where it no longer makes sense anyway.


Perl 6 language is not backwards compatible with Perl 5, so C<use 5> in Perl 6 should not just mean "Perl v5.0.0 or higher required" like it does now, but rather "v5.0.0 or higher, but lower than v6.0.0". C<use 5> and C<use 6> should disambiguate between Perl 5 and 6 in a program run by perl 6 interpreter.

C<package> just implies C<use 5>
C<class> et al implies C<use 6>

There is already a command line switch for one-liners "-M6" which works as it should, without any changes to perl 5:

$ perl -M6 -e 'print "ok"'
Perl v6.0.0 required--this is only v5.6.1, stopped (did you mean v6.0.0?).
BEGIN failed--compilation aborted.

(There might be a new switch "-6" introduced, which could mean "-M6" for:

perl -6e '...'

or maybe even "-6" could mean "-M6 -e" so this would work:

perl -6 '...'

making the "-6" a Perl 6 equivalent to "-e" which itself would always introduce Perl 5 code, allowing all of the existing one-liners to keep working. In any way, simple "perl -e" should default to Perl 5.)

When the perl binary name ends with a version number, the -MVERSION might be implied, so "perl6" or "p6" (I'd love perl6 to have p6 as a standard link) would mean "perl -M6" much like egrep is the same as "grep -E".

(It is not enough to match a digit "6" at the end, since perl-5.6 should mean "perl -M5.6" and not "perl -M6" but /(\d+(?:\.\d+)*)$/ (perl5-style regex) should be ok.)

The most important thing would be that all of this different ways of switching between Perl 5 and 6 could consistently work as "use VERSION" (maybe giving a warning in the implicit "package" and "class" cases to catch errors in Perl 6, but maybe not) so this pathological case:

#!/usr/bin/p6 -M5
class main;
# A
use 5;
# B

would be exactly equivalent to:

#!/usr/bin/perl
use 6; # from the binary name
use 5; # from the -M5
use 6; # from "class"
class main;
# A
use 5;
# B

Now, it might be debatable whether the above code should be allowed or not. Maybe not. Maybe only one 5/6 disambiguation should be allowed, or all of them should be consistent in the entire file, or at least after the first non-C<use VERSION> statement. In any case I think it all could be just a syntactic sugar for a simple C<use VERSION>.

Such a disambiguated Perl 6 code would not be run by perl5 by accident, since "use 6" or -M6 will give a correct error, there should be no binary called perl6 and the -6 switch would not work. The C<use 5> or -M5 can already be used in Perl 5 programs.

The only change in current "use VERSION" meaning would be to make versions below 6.0.0 mean "VERSION or higher, but below 6; enter Perl 5 compatibilty mode" (which makes sense anyway, since it is no longer backwards compatible). This change is not needed in Perl 5.

Of course it would all be optional. In case of no "use VERSION" or -MVERSION with simple "perl" binary and no class or package, perl would do whatever is planned to do right now.

I believe it is consistent with all of the current plans and doesn't need any change to Perl 5. Any comments?

--
ZSDC



Reply via email to