Slashdot Mirror


Exegesis 6 (Perl 6 Subroutines) Released

chromatic writes "Perl.com has just published Damian Conway's Exegesis 6 which gives practical examples demonstrating how to use the new subroutine and method semantics in Perl 6. This is the companion to Larry Wall's Apocalypse 6 which discussed the changes planned for subroutines in Perl 6."

14 of 234 comments (clear)

  1. Keywords by Gortbusters.org · · Score: 4, Interesting

    The one thing that I always found unpleasant when moving between languages was the keywords... so, I picked up a C book, migrated to C++, then Java, picked up PHP along the way. Everything was fairly similar with keywords and syntax, and then perl threw a monkey wrench into the mix. I've never looked at python, are there similarities there or are the perl gurus guiding us through their path of enlightenment?

    --
    --------
    Free your mind.
    1. Re:Keywords by TheFlyingGoat · · Score: 2, Interesting

      I've found that Perl syntax is more like C++ than Java is. Similarily, if you know PHP, you basically know Perl.

      I learned Perl quite a few years ago, and use it on a daily basis. When I needed to use PHP for some large projects, I was able to learn it on-the-fly in under a week. Sure there's a few PHP functions I still don't know, but I'll probably never use them.

      The way I see the development of Perl is that they're making it backward-compatible enough for people to make an easy transition, while having it advance enough to make the transition worthwhile. They've even switched to calling Perl regex's "rules" so people don't confuse true regex's or even what other computer software refers to as regex's.

      --
      You have enemies? Good. That means you've stood up for something, sometime in your life. --Winston Churchill
    2. Re:Keywords by grennis · · Score: 1, Interesting

      Having a weakly typed language is not an advantage. Apparently, script programmers cant deal with specifying that something is an 'int' or 'float' or whatever. .NET has really solved this problem, but making it strongly typed, but every typed is derived from 'object', which has a pure virtual 'ToString' which allows you to easily convert anything to a string suitable for printing. Can you see the advantage here?

      int a=1;
      WriteLine("a is type {0} and has value {1}", a.GetType().ToString(), a.ToString());


      The beauty of it is when you translate the text. The translator now has option of moving parameters around inside the text. Awesome.

      Now go ahead and mod me down for saying something positive about .NET :(

  2. seems like by butane_bob2003 · · Score: 3, Interesting

    the language is becoming more obtuse if thats possible. The perl programmers I know don't get along well with other languages, mostly because they have spent so much time learning the intricacies of Perl syntax. Even coming from C, Perl syntax is unnatural. Seems like once you go Perl, you can never go back (or try to learn a new language). I've never met a perl programmer who could tell me what a design pattern is either. I guess they don't go for re-use much in perl progging. I think if I went to hell, satan would probably make me write a Perl parser. (without the help of Yacc)

    --


    TallGreen CMS hosting
    1. Re:seems like by jdavidb · · Score: 3, Interesting

      I viewed a presentation about design patterns at YAPC::NA::2002.

      I once had a software engineering professor who over a period of several weeks refused to believe me that Perl was an object-oriented language (like C++, not like Java or Smalltalk). He was finally convinced when he taught design patterns, giving the factory class as an example, and I said, "I did that this morning in Perl." His jaw dropped.

      I still consider myself a Perl programmer, but I was laid off last November and moved to a new job that is primarily Oracle PL/SQL programming. I only knew the bare minimum of PL/SQL, but already I am one of the guys people go to in this office when they have PL/SQL questions. I've helped about six people more experienced than me through fixing mutating table problems, and I'm learning more constantly through reading and experience.

      I credit my experience with Perl extensively for helping me to be a good PL/SQL programmer. In my experience, good Perl programmers (the ones you're likely to see speaking at a conference or writing a book) use the right tool for the job, constantly pick up new languages (Ruby and Python are pretty popular), and do a better job programming in those languages because of their Perl experience.

    2. Re:seems like by Angst+Badger · · Score: 4, Interesting

      Even coming from C, Perl syntax is unnatural. Seems like once you go Perl, you can never go back (or try to learn a new language).

      I came from C (not that I exactly left it) and I didn't find Perl unnatural, and it hasn't crippled me for other purposes, unless you count involuntarily prepending '$' to variable names in C after a long session of Perl coding. As far as I am concerned, there are only three major problems with Perl:

      1. Type sigils. The underlying theory necessary to implement variables without special leading characters dates back, oh, thirty years or so. (This is particularly egregious with PHP, where there is only one generic sigil for all types rendering them pointless anyway, but that's a separate gripe.) The '$' notation for shell scripts existed to simplify the ad hoc parsers most shells use; it has no place in a full-blown language.

      2. Complex data structures. Even C syntax for deeply nested pointers is cleaner than Perl. Mostly because of 1, above.

      3. Writing large applications in Perl depends totally on intense self-discipline as a programmer, and everything about Perl actively encourages you to break that discipline. TMTOWTDI, past a certain point, is a liability, especially with large development teams.

      Obviously, Larry and Co. feel differently about these things, but they drive me up the fnarking wall.

      I think if I went to hell, satan would probably make me write a Perl parser. (without the help of Yacc)

      If Satan really wanted to put the screws to you, he'd require yacc. (The inside joke, for those who aren't deeply into compiler design, is that Perl can't be parsed by a yacc parser because it's not even remotely context-free. Whether that's a good idea or not is a debate that goes back to the days of the ALGOL design committee. The practical effect is that the syntax of Perl is described not by a formal grammar but by the implementation itself, which makes it all but impossible to validate a competing implementation.)

      --
      Proud member of the Weirdo-American community.
  3. Any Sufficiently Advanced Language... by Vagary · · Score: 5, Interesting
    A disclaimer: I used to program Perl for a living, but we had a falling out some years ago (around 5.0?). So if you don't think there's any merit to what I'm saying, then feel free to consider this a troll:

    Shortly after I started reading Exegesis 6 I was somewhat frightened by how complex Perl had become since I stopped keeping track of updates. Of course scripting languages have always been known for borrowing the best from other programming languages, so I kept reading in the hopes that I'd recognise something. I saw some features like the is constant declaration and started worrying that maybe they'd decided to borrow some features from the very popular but insanely evil Visual Basic. But then I saw this:

    type Selector ::= Code | Class | Rule | Hash;

    and realised that, just as Python is (alleged to be?) adding Lisp-like features, Perl is adding ML-like features! That line above is (minus the '::' and ';') straight out of a Haskell program. Then I started to notice more Haskell-like syntax:

    • Anonymous function declaration syntax: -> $animal { $animal.size < $breadbox } would be (\animal -> animal.size < breadbox) in Haskell
    • Multisubs are like pattern matching: multi sub feed(Cat $c) {...} multi sub feed(Lion $l) {...} would be
      feed (Cat c) = ...
      feed (Lion l) = ...
    • New infix operator definitions: infix:~|_|~ would be the function named (~|_|~)
    • Junctions are like list comprehensions: all(newvals) would be [x | x <- newvals] (it almost seems like junctions are lazy from the way Damian talks about them?!)

    And I'm sure a more thorough reading would turn up even more. (For example, the smart-match operator reminds me of the type inferences done in a Hindley-Milner type system.) So it appears that any sufficiently advanced language contains an implementation of a purely functional language, not specifically Scheme. :) Has Damian (who certainly has Haskell exposure) or Larry ever mentioned any of these influences?

  4. Forgot Currying! by Vagary · · Score: 2, Interesting

    One more thing:
    I'm really happy to see Perl include currying, I can't think of a programming language that I would be completely happy using without it.

  5. The World Needs Idealised Perl by Vagary · · Score: 4, Interesting

    In the denotational semantics community it was long ago decided that real programming languages are too messy and too much of moving targets for serious theoretical research. As a result, the most popular language is known as Idealised Algol which is a simplified and cleaned-up version of Algol-60 (I'm told Algol-W is the closest implementation).

    Now that Perl 6 has a rich operator definition system*, we can look forward to Idealised Perl (IP). IP would be a version of Perl stripped down to only the necessary syntactic building-blocks. Even if much of Perl 6 were implemented in C, it'd be possible to define all the syntax in terms of IP. If you're writing code for maintainability instead of prototyping, using IP as much as possible will ensure a smaller learning curve for non-gurus. IP will be simple enough to actually allow teaching Perl in universities.

    IP could be the elegant yet expressive language we all (whether we like Perl or not) wish Perl would be.

    * This is, IMO, the only really neat and elegant thing to come out of Perl 6 so far. If operators can be defined to the point where most mathematical formulae are executable, Perl will become a revolutionary tool.

    1. Re:The World Needs Idealised Perl by axxackall · · Score: 2, Interesting
      At the beginning there was LISP, the language with the biggest language report. You don't like various Perl assignments? How about various Lisp quotes?

      Then they decided to idealize it and created Scheme - the language with the smallest language report. Both languages are good, but both language have lost their popularity to first imperative and then OOP ones.

      I think the length of the language report won't help Perl either. People are already re-writing Perl code to Python. Why? Perhaps because they don't like to hack, they rather wanna design their programs. Perl coding style is hacking.

      --

      Less is more !
  6. A sharp detour from past Perls by Junks+Jerzey · · Score: 3, Interesting

    I like Perl. I use Perl often. I also know and use a variety of obtuse languages, including wacky ones like Forth, J, and Haskell, plus more traditional languages such as Python, C++, various BASIC derivatives, etc. In short, I'm not an anti-Perl troll. Blind language advocacy is for newbies.

    That said, I can't help but think that far too much thought has been put into Perl. One of Perl's real strengths has always been that it wasn't designed up front so much as accreting things have have been proven to work: hashes, formats, regular expressions, dynamic typing, back quoting, evaluation of variables inside strings, and so on. But Perl 6 is getting years of forethought, and all of that forethought is beginning to weigh things down. The old Perl way would have been to say "Look, now we have a simple parameter passing scheme like that one Python, one which has been proven to work." The Perl 6 way is to start with a series of odd little features, then keep modifying them and adding sugar to them until the end result, after a number of iterations of this, ends up being something that looks and works like Python's parameter passing scheme, but takes ten pages of explaining to fully explain,

    In short, this is the kind of thinking that begat PL/1 and Ada and other spectacularly complex languages.

    1. Re:A sharp detour from past Perls by demi · · Score: 2, Interesting
      ...but it has a lot of it already there,

      I'm curious what you think is coming in Perl6 that Python already has. The exception mechanism I suppose, and mixed positional, named and optional parameters. Anything else?

      and a lot of the other stuff isn't necessary because that's just not the way things work in Python.

      The reason people get into flamewars over Python vs. Perl is because of this philosophy: if Python doesn't do (or doesn't do well) what you want it to do, there must be something wrong with you. I use both, and I can't tell you how many times I've pointed out something I didn't like in Python, only to be told by a Pythonista that therefore I must be doing it wrong. Can't find the block end? Your blocks must be too long! Want more than a simple statement in lambda? That's not its purpose! Want declarative syntax? You don't need it!

      To be fair, Perl is letting you limit the incoming parameters via code, whereas Python limits them via philosophy ("Better to ask forgiveness")... but for all that verbiage, that's about all Perl 6 can do with parameter passing that Python can't.

      Could you clarify? Because I can't grasp what you're saying here. Are you saying that the only thing you can do with parameters in Perl over Python is "everything Python doesn't want you to do"? Or what?

      Anyone adding pipelines to code I have to subsequently maintain will be shot without trial.

      I actually think Damian's article does a pretty good job of showing the opposite: sometimes, a pipeline would be much easier to read than rabid nesting.

      I'm not 100% on board with all the Perl6 stuff either (in particular, I'm not sure I'm down with all the punctuation-based modifiers to the parameter list--there are a lot of them in the Apocalypse that aren't covered in the Exegesis).

      --
      demi
  7. Re:Troll-by-reference by Anonymous Coward · · Score: 2, Interesting

    Probably because he doesn't know what he's talking about, and there are numerous errors in his post.

    For example, he claims that each variable has its own prefix in Perl 5. That is completely false. A "variable" in perl is a reference to a typeglob, which contains memory slots for each type of value a "name" ( variable ) in perl can store: a scalar, a hash, an array, a filehandle, and a subroutine. The prefixes before a name in perl determine which slot you access ( it is the context you are calling the variable in ).

    For instance, @var for the array slot, $var for the scalar slot, %var for the hash slot, &var for subref, etc.

    Each "variable type" does NOT have its own prefix. The prefixes specify the context that the variable is being called in.

    By the way, *var references the entire "typeglob" at once, allowing you to do things like:

    $var1 = "name";
    @var1 = (1,2,3);

    *anothervar = *var;

    print $var1
    name
    print $var1[1]
    2

    Maybe if the person actually knew anything at all about perl, then his post would actually be worth paying attention to.

  8. Re:Holy syntax overload batman! by _ska · · Score: 2, Interesting

    ''Now, that being said, I would argue that Perl 5 already presents 99% of Lisp's flexibility. Perl 6 leap-frogs Lisp by presenting Lisp's flexibility in a package that is far easier to use (though, as you point out, perhaps not easier to LEARN).''

    Ok, thats funny. I can't speak to the flexibility of Perl 6, but you are on some serious chemicals if you argue that perl5 has 99% of Lisps flexibility.

    Perl has some real strengths (and real weaknesses, of course), but it is pushing it to claim it even approaches 50% of the flexibility of lisp. I would put it closer to 20%, but perhaps could be argued upward a bit. We are talking about *flexibility* here, not best-language-cause, so
    here are just a few of the reasons perl is way behind lisp (let alone 20 years ago lisp (cltl1)) in flexibility:

    'defmacro (there goes 30% right there)

    'defgeneric & 'defclass (don't talk to me about perls alleged object system.)

    'compile

    closures
    introspection
    semantic sanity
    read/write symmetry
    applicative programming that works
    decent numerics

    the list goes and on....