Slashdot Mirror


What is Perl 6?

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

19 of 343 comments (clear)

  1. Who cares what Perl 6 is.. by ForeverFaithless · · Score: 2, Informative

    ..now that we got Ruby.

    --
    Mark Kretschmann - Amarok Developer, KDE Member
  2. Re:10 Years Overdue by chromatic · · Score: 5, Informative
    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.

  3. Re:My short experience with perl... by rsidd · · Score: 1, Informative
    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]
    $

  4. Re:My short experience with perl... by cliveholloway · · Score: 2, Informative
    use Data::Dumper 'Dumper';
    my $LoL = [[1,2],[3,4],5,[6,7,8]];
    print Dumper $LoL;
    Errr??
    --
    -- Trinity in high heels carrying a whip: The donimatrix - there is no spoonerism
  5. Re:My short experience with perl... by cliveholloway · · Score: 1, Informative

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

    --
    -- Trinity in high heels carrying a whip: The donimatrix - there is no spoonerism
  6. PUGS by putko · · Score: 3, Informative

    Here http://www.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.

    --
    http://www.thebricktestament.com/the_law/when_to_s tone_your_children/dt21_18a.html
  7. Re:My short experience with perl... by cliveholloway · · Score: 4, Informative

    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.

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

    --
    -- Trinity in high heels carrying a whip: The donimatrix - there is no spoonerism
  8. Re:No language that I like better by Lisandro · · Score: 4, Informative

    Can you recommend a resource for OOP with Perl?

    Right now i found all i needed in the Perl.org site - this OO tutorial for Perl is pretty complete. There's also this one, 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.

  9. Re:Hear me True Gods of Interoperability by chromatic · · Score: 2, Informative

    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.

  10. Re:My short experience with perl... by forty7 · · Score: 3, Informative

    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!

  11. Re:My short experience with perl... by BadAnalogyGuy · · Score: 5, Informative
    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.
  12. Re:My short experience with perl... by forty7 · · Score: 3, Informative

    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.

  13. Amber for Parrot by ribuck · · Score: 2, Informative
    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.

  14. Re:My short experience with perl... by PommeFritz · · Score: 2, Informative

    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.

  15. Re:No language that I like better by Metasquares · · Score: 2, Informative

    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.

  16. Re:What is Perl 6? by CRCulver · · Score: 2, Informative

    If you want to learn something on the leading edge you might even want to consider learning Io No books for Io as yet, but it seems to be be generating buzz among the early adopters (the sort of folks who were using Ruby five years ago).

    I've heard of Io before, but I find it hard to take a language seriously if it has its own UI toolkit. That for me implies a lack of abstraction, a philosophy of micromanagement, and--since there's already plenty of existing UI toolkits for which its a cinch to write bindings--a sentiment of Not Invented Here. Let the language be designed so that it steps out of the user's way on many fronts and encourages him to code with whatever already-available libraries might be available.

    FWIW, if the OP wants to learn another language beside Perl 5 just in case he were tasked to maintain some outside project, I'd recommend Python. O'Reilly's Learning Python and Programming Python are dynamite books.

  17. Re:Perl 6 is evolving the language into awesome! by TheLink · · Score: 3, Informative

    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.

    --
  18. Re:No language that I like better by dubl-u · · Score: 2, Informative

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

  19. Actually, I found an example of what you mention by 5n3ak3rp1mp · · Score: 2, Informative

    I believe that this is what you are slandering on about, and this 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).