Live data from Hacker News

Differences Between Perl 5 and Perl 6

design.perl6.org

11–20 of 127 posts

Re: Differences Between Perl 5 and Perl 6

#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.#;
Similarly:

  Was:    $#array+1 or scalar(@array)
  Now:    @array.elems
(All IMHO)

Re: Differences Between Perl 5 and Perl 6

#12
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…

this is a typo error actually: Now: my $len = $string.length;

http://doc.perl6.org/type/Str#method_length

EDIT: I don't see any contact section on their page to let them know

Re: Differences Between Perl 5 and Perl 6

#13
post #9

Earlier quoted context omitted.

It 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

That'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.

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

Re: Differences Between Perl 5 and Perl 6

#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?

Re: Differences Between Perl 5 and Perl 6

#16
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…

I agree with you. I think a chars functions isn't the best name in the sense that it returns the length of the string instead of a list of its individual characters.

It makes me wonder if this will be the case for other methods in the language.

Re: Differences Between Perl 5 and Perl 6

#17
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…

this is a typo error actually: Now: my $len = $string.length; http://doc.perl6.org/type/Str#method_length EDIT: I don't see any contact section on their page to let them know

method length

Perl 6 does not have a length function. See chars or elems.

Re: Differences Between Perl 5 and Perl 6

#18
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…

this is a typo error actually: Now: my $len = $string.length; http://doc.perl6.org/type/Str#method_length EDIT: I don't see any contact section on their page to let them know

length is gone. See:

http://design.perl6.org/S29.html#Obsolete_Functions

"length()

This word is banned in Perl 6. You must specify units. In practice, this probably means you want Str.chars(), although it could be Str.bytes(), or even something else. See S32-setting-library/String for details."

Re: Differences Between Perl 5 and Perl 6

#19
post #9

Earlier quoted context omitted.

That'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.

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 of the semicolon form.

Re: Differences Between Perl 5 and Perl 6

#20
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…

Just keep that codebase in Perl 5? Perl 6 isn't a replacement for Perl 5. It's a whole new language. Perl 5 is still actively maintained and used.
Post reply on HN