Follow Slashdot blog updates by subscribing to our blog RSS feed

 



Forgot your password?
typodupeerror
×

Perl 5.10, 20 Year Anniversary 304

alfcateat writes "Perl 1 was released to the public by Larry Wall 20 years ago yesterday. To celebrate, Perl5Porters have released Perl5.10, the latest stable version of Perl 5. Happy Birthday Perl! Perl 5.10 isn't just a bug fix version: it's full of new features that I'm eager to use: named captures in regular expressions, state variables for subroutines, the defined-or operator, a switch statement (called given-when, though), a faster regex engine, and more. You can read more about the changes in perldelta."
This discussion has been archived. No new comments can be posted.

Perl 5.10, 20 Year Anniversary

Comments Filter:
  • by chris_eineke ( 634570 ) on Wednesday December 19, 2007 @10:20AM (#21750988) Homepage Journal

    Yeah, and who needs if statements anyway,
    You wrote something accidentally insightful. Look at the following expression:
    (if (> 3 2) 5 4)
    which obviously evaluates to 5. But you know what? You can eliminate the if operator entirely if you let > (and any other predicate) return a two-ary function:
    (define true (x y) (x))
    (define false (x y) (y))

    and stuff the arguments into separate functions for deferred evaluation:
    ((> 3 2) (lambda () 5) (lambda () 4))
    :-)
  • by chicoryn ( 989443 ) on Wednesday December 19, 2007 @10:47AM (#21751278)

    Switch statements are syntactic sugar. They're really not needed. Nested if/then/else do the same thing.

    They do not! Not only do they increase readability of the code in many cases they do not even generate equivalent RTL. When you do a if-else if-else... you tell the compiler that it MUST check the first condition before the second, a subtle but important difference. What this means to the compiler is that an if-else if-else... must have O(n) complexity!

    An switch statement on the other tell the compiler each item is independent of any other (and comparison is generally enforced as side-effect free). This means a switch statement can be converted to a binary-search or even a jump-table giving us a best-case complexity of O(1).

    As you can see they are hardly equivalent but a really good compiler might be able to convert a if-else if-else... to a switch statement. But considering a switch statement is usually easier to read, write and understand in the first place why bother?

  • Re:Hmmmmmm (Score:5, Interesting)

    by ricegf ( 1059658 ) on Wednesday December 19, 2007 @11:12AM (#21751524) Journal

    are there any other reasons for working on this project?

    If Parrot becomes "efficient enough", then hosting Perl, Python and Ruby on Parrot should permit writing programs in a mixture of all three. Python has a very extensive library, but I certainly wouldn't mind having all of CPAN for which to choose as well - or access to Rails, for that matter. (Yes, I know, much of Rails' value is in its elegant fit to Ruby syntax, but I'd still like access from Python. Call me a library pack rat. :-)

    For another example of recent interest to me, Perl and Ruby have excellent integrations with GraphicsMagick; Python has Python Image Library (PIL) instead. Why can't I choose the graphics library I want from any of the big three dynamic languages?

    Nor would Parrot implementations of those languages need to replace the main implementations to be useful. The JVM has Jython and JRuby, granting access to Java libraries like Swing. Similarly, Microsoft's .NET has IronPython and IronRuby to avoid the much-maligned VB6. Interoperable implementations of Perl 6, Python 3, and Ruby 2 on Parrot would be very nice indeed.

    Well, for a dynamic language junkie like me, at least. ;-)

  • by johannesg ( 664142 ) on Wednesday December 19, 2007 @11:48AM (#21751910)
    And how is ((> 3 2) (lambda () 5) (lambda () 4)) better than (if (> 3 2) 5 4), especially considering that you are apparently changing the meaning of true and false to something that is only extremely locally true? (disclaimer: ((lisp) ((not) (me)) () (speak))). This is a serious question, btw: is there really some advantage to doing this the difficult way?

    And then I'm carelessly skipping over 3 > 2 ? 5 : 4, which is of course the *correct* solution ;-)

One man's constant is another man's variable. -- A.J. Perlis

Working...