Catch up on stories from the past week (and beyond) at the Slashdot story archive

 



Forgot your password?
typodupeerror
×
Perl Programming

What is Perl 6? 343

chromatic writes "Perl.com has a new article entitled What is Perl 6?. It analyzes the changes to the language in light of the good and bad points of Perl 5 and provides new information about the current state of the project: Perl 6 exists, you can write code in it today, and it's more consistent and easier to use than Perl 5."
This discussion has been archived. No new comments can be posted.

What is Perl 6?

Comments Filter:
  • by ForeverFaithless ( 894809 ) on Tuesday January 17, 2006 @03:13AM (#14488656) Homepage
    ..now that we got Ruby.
  • Re:10 Years Overdue (Score:5, Informative)

    by chromatic ( 9471 ) on Tuesday January 17, 2006 @03:26AM (#14488692) Homepage
    Over 10 years later, perl 6 is still in beta mode.

    Did you read the same article I wrote or is your post from the mysterious future? Larry announced Perl 6 in the summer of 2000.

  • by rsidd ( 6328 ) on Tuesday January 17, 2006 @03:34AM (#14488712)
    How do you write nested lists such as [[1,2],[3,4],5,[6,7,8]]?

    In Perl? Exactly that way.

    Indeed?
    $ cat list.pl
    @a = ((1,2),(3,4),5,(6,7,8));
    print @a[0], " ", @a[1], " ", @a[2], " ", @a[3], " ", "\n";
    print $a[0], " ", $a[1], " ", $a[2], " ", $a[3], " ", "\n";
    $ perl list.pl
    1 2 3 4
    1 2 3 4
    $ cat list.py
    a = [[1,2],[3,4],5,[6,7,8]]
    print a[0], " ", a[1], " ", a[2], " ", a[3]
    $ python list.py
    [1, 2] [3, 4] 5 [6, 7, 8]
    $

  • by cliveholloway ( 132299 ) on Tuesday January 17, 2006 @03:35AM (#14488717) Homepage Journal
    use Data::Dumper 'Dumper';
    my $LoL = [[1,2],[3,4],5,[6,7,8]];
    print Dumper $LoL;
    Errr??
  • by cliveholloway ( 132299 ) on Tuesday January 17, 2006 @03:50AM (#14488755) Homepage Journal

    Yes, indeed. So you change the arrayref of arrayrefs in your first post to an array of lists in the parent code and wonder why it doesn't work?

    Let's assume you actually do want a list of lists and we'll brace the 5 and make it an array of arrayrefs.

    @a = ([1,2],[3,4],[5],[6,7,8]);
    print "@{$a[0]} - @{$a[1]} - @{$a[2]} - @{$a[3]} \n";

    Or, sticking to your original arrayref of arrayref notation:

    $a = [ [1,2],[3,4],[5],[6,7,8] ];
    print "@{$a->[0]} - @{$a->[1]} - @{$a->[2]} - @{$a->[3]} \n";

    cLive ;-)

  • PUGS (Score:4, Informative)

    by putko ( 753330 ) on Tuesday January 17, 2006 @03:56AM (#14488774) Homepage Journal
    Here http://www.pugscode.org/ [pugscode.org] is something on the PUGS project, which is making an implementation of Perl 6 in Haskell, conformant to the spec.

    Apparently they are having a lot of fun.
  • by cliveholloway ( 132299 ) on Tuesday January 17, 2006 @03:59AM (#14488779) Homepage Journal

    Oh please.

    "Especially when every perl doc I see around tells me to use curved parentheses for lists, and @ prefixes for variables that refer to them..."

    How hard did you look, really? If you go to Google and type in perl list of lists, the FIRST link takes you here [perl.com].

    And within 1/2 a page, you see this:

    # assign to our array a list of list references
    @LoL = (
    [ "fred", "barney" ],
    [ "george", "jane", "elroy" ],
    [ "homer", "marge", "bart" ],
    );

    print $LoL[2][2];
    bart

    Damn anti-Perl trolls :-)

  • by Lisandro ( 799651 ) on Tuesday January 17, 2006 @04:12AM (#14488807)
    Can you recommend a resource for OOP with Perl?

    Right now i found all i needed in the Perl.org site - this OO tutorial [perl.org] for Perl is pretty complete. There's also this one [perl.org], which is oriented to begginers.

        In fact, i always keep a browser window open to Perl.org when i'm coding Perl - the tutorials are very nice, but the function reference has been priceless to me.
  • by chromatic ( 9471 ) on Tuesday January 17, 2006 @04:24AM (#14488847) Homepage

    That's what Parrot's NCI layer does. It's a foreign function interface to shared libraries. It's much nicer than Perl 5's XS.

  • by forty7 ( 722797 ) on Tuesday January 17, 2006 @04:29AM (#14488863)
    Yes, that's really intuitive, thanks. Especially when every perl doc I see around tells me to use curved parentheses for lists, and @ prefixes for variables that refer to them, and I have no clue what data structure you've used above.

    You're right; you do need curved parens for real lists. It may be helpful to think of the @ mark as referring to multiple values, rather than to a list specifically. It's also used for list and hash slices, like this: @list[1,3,5] and @names{'tom', 'dick', 'harry'} (Both of those expressions really just evaluate to lists, but, particularly with the hash slice, that's not necessarily obvious).

    The other responders, in their haste to point out how much perlier-than-thou they are, have glossed over the fact that 'my $list = [[1,2],[3,4],5,[6,7,8]];', as you've pointed out, doesn't exactly produce a list of lists. It produces a data structure that's close enough to a list of lists that they can call it that without being entirely wrong.

    (Warning: Perl content. I love Perl, so it'll probably sound like I'm rambling. My apologies.)

    You can't directly create a list of lists in Perl. Not possible, because they'll get flattened. But what you can do is create a list of *references* to lists. There are two ways to do this:
    my @list1 = (1, 2, 3);
    my @list2 = (4, 5, 6);
    my @combined = (\@list1, \@list2);

    Or:
    my @combined = ([1, 2, 3], [4, 5, 6]);

    This second syntax is called the anonymous list syntax.

    The upshot is that lists are surrounded by (), as you already know, but that by replacing them with [], you get a reference to a list with no other name. The same can be done for hashes with {}, which means that all Perl data structures can be arbitrarily nested.

    So, your Python example, in Perl, would create a reference to a list of references to lists. Its elements would be accessed like this:
    my $list = [[1,2],[3,4],5,[6,7,8]];
    print $list->[0][1] # prints 2

    The -> is used for dereferencing, but Perl is clever enough to figure out that the value of '$list->[0]' is also a reference, and doesn't require you to write the -> between [0] and [1].

    You could also write your example like this:
    my @list = ([1,2],[3,4],5,[6,7,8]); # note the ()

    print $list[0][1] # *also* prints 2!

    It turns out Perl is *still* clever enough to figure out that $list[0] is a reference, and will automatically dereference it for you. No -> required.

    I hope this helps clear things up a bit!
  • by BadAnalogyGuy ( 945258 ) <BadAnalogyGuy@gmail.com> on Tuesday January 17, 2006 @04:31AM (#14488870)
    This is one area where the Perl docs (as detailed as they may be) fail new users.

    Intuitively, a new user would look at the TOC and see perldata "Perl Data Types" and think that the complete definition of the 3 main Perl data types would be described. So rsidd looks for instructions on creating multidimensional arrays, sees "List value constructors" and gets this:

    LISTs do automatic interpolation of sublists. ... arrays and hashes lose their identity in a LIST... To make a list reference that does NOT interpolate, see the perlref manpage.


    So they head over to perlref (an extra level of indirection) and notice in Item 2:

    A reference to an anonymous array can be created using square brackets:

            $arrayref = [1, 2, ['a', 'b', 'c']];

    Here we've created a reference to an anonymous array of three elements whose final element is itself a reference to another anonymous array of three elements. (The multidimensional syntax described later can be used to access this. For example, after the above, $arrayref->[2][1] would have the value ``b''.)


    But this isn't really easy to understand. Why does he need an arrayref when he wants an array?

    @array = [1, 2, ['a', 'b', 'c']];

    That isn't the same as what he wants. In fact, it's not what you'd expect from DWIM. It's a single entry array, not a multidimensional array. It's not even a list of lists (unless you perform a little magic on it).

    So finally after struggling with this and ending up with some ugly monstrosity like the following:

    @array = @{[1,2,\@{['a','b','c']}]};

    Now his code works, but it isn't very easy to understand, and the maintainers of this code are going to tell everyone how evil and illegible Perl is because the programmer here couldn't figure out how to make a multidimensional array.

    The only FAQ entry with the term "multidimensional" in it refers to some DBM-specific topic that doesn't seem to have any relation to the problem at hand. While "list of lists" may be the preferred term in the Perl community, it would be nice to have a FAQ entry like "How do I create a multidimensional array?"

    As you've mentioned, perllol has the exact syntax of how to do this. Unfortunately for our poor programmer, the link to that is buried in the See Also section alongside perldsc (which is large and contains quite a bit of irrelevant information like 'use strict' information, while at the same time not providing very detailed information about the data structures themselves). The very first 'perldoc perllol' page displayed gives the answer immediately:

    An array of an array is just a regular old array @AoA that you can get
    at with two subscripts, like $AoA[3][2]. Here's a declaration of the
    array:

            # assign to our array, an array of array references
            @AoA = (
                          [ "fred", "barney" ],
                          [ "george", "jane", "elroy" ],
                          [ "homer", "marge", "bart" ],
            );

            print $AoA[2][2];


    Why is it so hard to get to this simple explanation? Why should a neophyte have to go through two documents to finally get to perllol? The FAQ should describe the technique using "multidimensional" as a keyword.

    I love Perl, and I love the depth and breadth of the Perl docs, but they are difficult to navigate for Perl neophytes.
  • by forty7 ( 722797 ) on Tuesday January 17, 2006 @04:38AM (#14488893)
    Dang it, copy-and-paste missed a couple of sentences at the end. Here they are, in context:

    It turns out Perl is *still* clever enough to figure out that $list[0] is a reference, and will automatically dereference it for you. No -> required. The beauty of this automatic dereferencing is that it allows Perl to DWIM (Do What I Mean): Perl is perfectly content to let you pretend that a 'list of *references* to lists' is actually just a 'list of lists'. The downside of the automatic dereferencing is that it turns the easy-to-miss difference between '((1,2),(3,4))' and '([1,2],[3,4])' into Just Another Bit Of Fiddly Syntax To Remember.
  • Amber for Parrot (Score:2, Informative)

    by ribuck ( 943217 ) on Tuesday January 17, 2006 @08:13AM (#14489452)
    For instance I very much like the look of Amber as a scripting language with maintainability in mind

    Thanks for your interest in Amber. I'm the author of Amber for Parrot which, although in the early stages of development, will hopefully become sufficiently complete to be really useful, sometime this year.

    Although Perl 6 is a nice cleanup and enhancement, the Parrot Virtual Machine is going to be far more important to the computing world than Perl 6. Parrot will do for scripting languages what the JVM and .NET are doing for compiled languages.

    Parrot is not yet functionally complete, but it's genuinely usable. It has been a delight to to target Parrot, because most things just work - and when they don't, the Parrot developers have gone out of their way to help.

    Parrot development has been pretty rapid recently - although you can't always tell from the documentation which often lags behind.

  • by PommeFritz ( 70221 ) on Tuesday January 17, 2006 @08:25AM (#14489482) Homepage
    Python's list comprehensions are generators. Look it up what this means. The infinite Fibonacci sequence can be written in Python as a generator function:

    def fib():
            e=0
            f=1
            while True:
                    yield f
                    e,f = f,f+e

    You can print it like this:

    for f in fib(): print f

    but that wouldn't bee too convenient, other than to see Python's long-number feature :)

    More interesting is combining it with another generator function, one that only returns the first N numbers of the given generator:

    def firstn(g, n):
            gen=g()
            for i in range(n):
                    yield gen.next()

    print list(firstn(fib, 10))

    The explicit conversion to a list is because otherwise you would see that the object you're trying to print is not the list itself, but the generator that will build the list for you one element at a time.
  • by Metasquares ( 555685 ) <slashdot.metasquared@com> on Tuesday January 17, 2006 @09:35AM (#14489761) Homepage
    Poor OOP support is an understatement. Classes are really just blessed hashes in Perl 5. You can't do encapsulation (without special modules, anyway) and even inheritance looks like it was just tacked on. (@isa?)

    I'm very glad that Perl 6 will have better thought out OOP support. It would have made a recent 7,500 line project I worked on much smaller, easier, and more stable.

    You're correct, though; it's a very useful language outside of the poor OOP.
  • Comment removed (Score:3, Informative)

    by account_deleted ( 4530225 ) on Tuesday January 17, 2006 @10:43AM (#14490155)
    Comment removed based on user account deletion
  • by TheLink ( 130905 ) on Tuesday January 17, 2006 @11:34AM (#14490519) Journal
    Because in Perl
    "1"."2" eq "12"
      and
    1 + 2 == 3

    If a loosely typed language is using + for concatenation, it's poorly designed (you'd end up typing more to specify what you want done).

    You need to know that the concatenation of two variables is not the same as adding them together.

    Slightly relieved that Perl 6 switched from using underscore to tilde for concat - underscore is overloaded with so many other tasks already. Unfortunately ~ still requires shift to be pressed on my keyboards, but I guess they are running out of symbols, and at least I think ~ won't require you to keep putting spaces around it to disambiguate it from other meanings.
  • by dubl-u ( 51156 ) * <2523987012@pota . t o> on Tuesday January 17, 2006 @02:22PM (#14492132)
    Ignore the analogies, OOP has nothing to do with obkects at its core. OOP is basicly encapsulation and interfaces.

    A reasonable theory, but you're missing half of the power of object-oriented languages. Read Evans' fantastic book Domain-Driven Design [domaindrivendesign.org] for the other half. You will discover than a lot of people, even many of those writing "Intro to Java" books, made the transition to OO languages without ever learning OO design.
  • by 5n3ak3rp1mp ( 305814 ) on Tuesday January 17, 2006 @06:06PM (#14494447) Homepage
    I believe that this [kcrug.org] is what you are slandering on about, and this [kcrug.org] is one possible workaround.

    I asked around in #ruby-lang about this, and this is not only the #1 bug in Ruby, it will be fixed in 2.0.

    If you had a more concrete broken-lexical-scoping example, please feel free to provide.

    In the meantime, if this is the biggest Ruby bug, I'm planning on sticking around for sure ;) The readability alone is a huge win over other languages (IMHO).

He has not acquired a fortune; the fortune has acquired him. -- Bion

Working...