Live data from Hacker News

Differences Between Perl 5 and Perl 6

design.perl6.org

21–30 of 127 posts

Re: Differences Between Perl 5 and Perl 6

#22
post #11

Was: my $len = length($string); Now: my $len = $string.chars; My intuitive interpretation of that syntax would be "given a string, return a sequence containing its characters, in order". Or is that overlading on return type, and do you get the behavior I would find intuitive if one assigns to an array? Even if that is true, I find that ugly. I would prefer more explicit code, for example my $len = $string.chars.#; Si…

Every Perl expression has a context, and context is as central to Perl as types are to some other languages. It's first chapter material in any Perl book. It's not "overloading on return type" strictly speaking, but that's what the syntax looks like.

An array (of characters in your example) in a scalar context is the length of the array. I don't know if that's whats happening here, but that's how you do it everywhere else in Perl so it would make sense to do it on strings too.

Re: Differences Between Perl 5 and Perl 6

#24
post #15

To reuse the recent slogan, the only thing that changed is everything. It's a new language with its own internal logic. I used (and still use) Perl 5 because it made some specific things easy to make (various processing of data). I still don't know for which kind of tasks Perl 6 is the best choice. But maybe the language is simply too young for it to be obvious?

Perl6 is really a strict supserset of Perl5 in this way.

Perl6 is at least as good as Perl5 for everything Perl5 is good at.

But Perl6 is way, way more than that.

Re: Differences Between Perl 5 and Perl 6

#25

Earlier quoted context omitted.

From 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 ;)

There are numerous error messages that highlight perl 5 isms e.g. > say $#array; ===SORRY!=== Error while compiling Unsupported use of $#variable; in Perl 6 please use @variable.end and package foo; ===SORRY!=== Error while compiling 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…

Yes, 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 
    Unsupported use of ? and : for the ternary conditional operator; in Perl 6 please use ?? and !!
    at :1
Or:

    > loop(my $i = 0; $i :1
Easily the nicest error reporting I've seen in a compiler.

Re: Differences Between Perl 5 and Perl 6

#26
post #15

To reuse the recent slogan, the only thing that changed is everything. It's a new language with its own internal logic. I used (and still use) Perl 5 because it made some specific things easy to make (various processing of data). I still don't know for which kind of tasks Perl 6 is the best choice. But maybe the language is simply too young for it to be obvious?

Perl6 is really a strict supserset of Perl5 in this way. Perl6 is at least as good as Perl5 for everything Perl5 is good at. But Perl6 is way, way more than that.

I'll probably be trouted by a Perl monk for saying it, but sometimes less is more.

Re: Differences Between Perl 5 and Perl 6

#27
post #6
post #4

Note that its more or less "how to write perl 5 in perl 6" Sorta like the old F2C, Fortran to C, converter. You don't get idiomatic C, but you do get a fortran program that compiles and runs as a C program, more or less. Some parts of perl6 are annoyingly urbit-y, come on, you guys just had to rename ARGV and rename scalar and the for-foreach transition is ridiculous. I suspect at least a decade of people pointing at…

It might be too much stress or too little coffee, but I don't understand the last part. Why would you need to replicate behaviour and tests? You mean it will take time before you trust the "use Perl 5 code in Perl 6" bridge that is worked on, so it isn't enough to run the Perl 5 tests and then use that code in Perl 6? (Or you think there will be bad interactions with Moose and Perl 6 OO?) Edit: Huh, I was shortly un-…

> Edit: Huh, I was shortly un-hellbanned and am Hellbanned again since the previous comment didn't live up to some interesting-level standard? :-)

Maybe your comment got rescued by someone using the new vouch feature?

Re: Differences Between Perl 5 and Perl 6

#30
post #10
post #8

Earlier quoted context omitted.

Any 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.

`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.

Oh! I could have sworn it was necessary. My bad.
Post reply on HN