4 ms·
One thing that bugs is that perl5 code could potentially run with perl6. Is there any mitigation for that?
by Paul_S 11y ago
One thing that bugs is that perl5 code could potentially run with perl6. Is there any mitigation for that?
- jayvanguard 11y agoIt was explicitly not a design goal to be backwards compatible. "In exchange for breaking backwards compatibility, at least at the language level, Perl 6 offers plenty of high-powered language concepts that Perl 5 didn't support..." http://www.perl.com/pub/2006/01/12/what_is_perl_6.html http://www.perl.com/pub/2006/01/12/what_is_perl_6.html
- maw 11y agoThat's not what I read the GP post as saying though. Rather, that the perl 6 interpreter could run code written as perl 5 (and never ported). With their different semantics, the results would be unpredictable and often undesired.
- kylebgorman 11y agoFrom this document, the chance that a perl 5 script is syntactically valid (but semantically different) perl 6 is awfully low. Now if the errors that arose said that you might be trying to execute perl 5 as perl 6, that'd be cool ;)
- donaldihunter 11y agoThere are numerous error messages that highlight perl 5 isms e.g. > say $#array; ===SORRY!=== Error while compiling <unknown file> Unsupported use of $#variable; in Perl 6 please use @variable.end and package foo; ===SORRY!=== Error while compiling <unknown file> This appears to be Perl 5 code. If you intended it to be Perl 6 code, please use a Perl 6 style declaration like "unit package Foo;" or "unit module Foo;", or use the block form instead of the semicolon form.
- amyjess 11y agoYes, these suggestions are among my favorite things about Rakudo. There are a lot more, too. Another example: > 1 == 1 ? "sane" : "insane" ===SORRY!=== Error while compiling <unknown file> Unsupported use of ? and : for the ternary conditional operator; in Perl 6 please use ?? and !! at <unknown file>:1 Or: > loop(my $i = 0; $i < 10; $i++) { say $i } ===SORRY!=== Word 'loop' interpreted as 'loop()' function call; please use whitespace around the parens at <unknown file>:1 Easily the nicest error reporting I've seen in a compiler.
- cytzol 11y agoAny Perl 6 code will have to include a `use v6;` instruction at the very top of the file, so there's no chance of Perl 5 code being confused for it. Is this what you mean? EDIT: this was completely wrong, see below.
- colomon 11y ago`use v6;` is not mandatory in Rakudo. Off the top of my head, I don't think it's mandatory in theory in Perl 6, either. However, it is widely used to mark Perl 6 code, because it gives you a nice clean error message if you accidentally try running it in Perl 5.
- cytzol 11y agoOh! I could have sworn it was necessary. My bad.
- perlgeek 11y agoYou should declare the version of your code. 'use v6;' for Perl 6 code (more specific versions will come up soon), and "use 5.014" for Perl 5.14, for example. This will give good error messages when trying to run your code with the wrong compiler.