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

21 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 ajs · · Score: 4, Informative
      Perl has keywords picked up from C (for, if, while, int, printf, etc.); BASIC (substr); Modula (module); CPP (defined); and many other sources. It's very much a post-modern language in the sense that it seeks to deconstruct all other languages and re-build itself in their images without actually being just a collage of their parts.

      HOWEVER, that being said Perl has a huge advantage over the keyword restrictions of most languages. I'll show you a sample of some code, and you tell me if you can see what the advantage is:
      $time = time();
      $localtime = localtime();
      print "UNIX timestamp $time is $localtime\n";
      The same goes (to a slightly lesser extent, since you don't *have* to use the prefix-sigle &) for subroutines and all of the other miscelaneous Perl data types that can be named (obviously those that cannot be named like stashes never conflict with a keyword).
    2. Re:Keywords by ajs · · Score: 4, Insightful

      Having a weakly typed language is not an advantage

      You're confusing variable glyphs with typing. While variable glyphs in Perl do indicate something about the typing, they are not type identifiers.

      I was pointing out the advantages of glyphs, not types.

      Apparently, script programmers cant deal with specifying that something is an 'int' or 'float' or whatever

      Script is a misused word here, since the term litterally means a collection of commands as a user would have typed them, and while you can write Perl code that looks kind of like that, it's certainly not the way Perl is used). Shell programs aren't even always scripts (just look at your average configure program). Don't contribute to watering down the word, especially if you're just doing so to make the "what makes us real programmers special" weak assertion.

      Ok, that said, Perl does offer typing, but only when you really need it. Since strong typing isn't needed in perl by default (Perl 5 and under have no real compilation mechanism, so the performance gains would be minimal), all you really need is to type *data* not *variables*.

      You can type data using any number of tools in Perl including pack, unpack, sprintf and vec.

      In Perl 6, there will be a just in time compiler, and eventually a stand-alone binary compiler. This introduces the need to access system types in a more rigorous way, and Perl 6 has typing features such as you would find in any other language. Of course, $x = $y will still work regardless of types (though it could cause a compile or run-time error if they are excplicitly incompatible, but that's not going to happen unless you really mean for it to). .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?

      That's the approach of about 5-10 DOZEN languages (literally) over the last 10-20 years. Let's not credit C# with the "innovation" of objects as the only first-class data types (I assume you mean C#, since .Net isn't actually a language, but a Microsoft product that encompasses the .Net runtime, which in turn encompases C#... kind of like calling Java JSP).

      Perl 6 is going down the same route as did Python (long before C#).

      Perl 5 has fairly primative roots, and given those roots its typing system made sense at the time. Perl 5 does also have a universal base-class for all objects, but not all types are objects in Perl 5. They will be in Perl 6.

  2. For those who don't know.... by ajs · · Score: 5, Informative
    The way Perl 6 is being developed is thus:
    • Everyone in the world had a chance to submit RFCs
    • Larry is taking each section of the 3rd edition Programming Perl and turning it into a white-paper on the way Perl 6 will work, using the RFCs that touch on that section of Perl as a sort of shopping list, and accepting, modifying or rejecting them as needed. These are called the Apocalypses.
    • After an Apocolypse is out, Damian starts working on some real-world examples to make it all more concrete. These are called the Exegeses. Sometimes these also have examples of syntax and semantics that have been worked out via the mailing lists
    • Eventually, this will lead to the Design Documents
    Hope that helps clear this up for those who aren't sure what's going on when they see a new Apocolypse or Exegesis come forth.

  3. oh yeah by tomstdenis · · Score: 5, Insightful

    sub Fahrenheit_to_Kelvin (Num $temp is rw) {

    Verbosity in coding, yeah that will go over well with people who are used to

    int lbn, rax, ... ; :-)

    Don't get me wrong I'm a big fan of Perl, but not for its completeness as a language but for the ability to quickly write small utils to parse text.

    But I suppose whatever floats peoples boats.

    Tom

    --
    Someday, I'll have a real sig.
  4. Re:For those who don't know.... by absolut_kurant · · Score: 4, Funny

    Thank God Damian isn't working on the Apocalypses...

    --
    Yes.
  5. Perl floats *all* boats by flicken · · Score: 5, Funny
    That's the point of Perl. If you don't want to use the verbosity of:

    sub Fahrenheit_to_Kelvin (Num $temp is rw) {

    You don't have to! You could just as well use:

    sub f2k ($temp) {

    Perl will allow either. It's your choice. You can do the quick one-off-hack-it-up-at-3am-after-two-large-pots-of- coffee, and you can have a large programming project that must be maintained for years to come.

    You have the choice. Pick whichever method fits the task at hand.

    --
    20 mil and I will! Learn Esperanto with 20M others.
  6. Re:Perl6 is a mistake by Ed+Avis · · Score: 4, Insightful

    BTW, a nondeterministic finite automaton is much less flexible than ordinary code; there are many things (checking for palindromes being the classic example) which code in a programming language can do but an NFA (and hence a regular expression) cannot. What you mean is that regexps provide a more concise syntax, and perhaps a more efficient implementation (since the regexp engine is in C).

    Perl's so-called regular expressions are not true NFAs however, because they have wacky things like backreferences. In fact they are NP-complete.

    --
    -- Ed Avis ed@membled.com
  7. Re:seems like by chromatic · · Score: 5, Insightful
    the language is becoming more obtuse if thats possible.

    Read the last page of Exegesis 6 to see the Perl 5 version of the code. It's astonishingly simpler and clearer in Perl 6.

    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.

    See the Inline modules on the CPAN.

    I've never met a perl programmer who could tell me what a design pattern is either.

    See Perl Design Paterns, an article on Perl.com.

    I guess they don't go for re-use much in perl progging.

    See the CPAN.

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

    I've read the Perl parser. You're right about this one.

  8. Holy syntax overload batman! by jtdubs · · Score: 5, Informative

    I've never seen a language with so much syntax. Perl 5 had more than enough, now they've more than doubled it.

    You have { } for blocks, and for automatically parameterized blocks (ie. anonymous functions).

    You have =, := and ::=, ~=, ~~, .... = does assignment, := does binding and ::= works at compile time and is normally used to define types and such, ~= is pattern matching, and I have no idea what ~~ does.

    You have the new <== and ==> pipeline operators. They are dataflow operators. Like so:

    $foo ==> my_func ==> $bar;
    is the same as
    $bar <== my_func <== $foo
    is the same as
    $bar = my_func($foo);
    is the same as ...

    You already had the $,@,%,& to prefix variables with.

    You have more uses for * now, as in slurpy arrays and splicing. As in, the * can make an array parameter slurp up all the remaining arguments, or it can make an argument flatten into a list of arguments.

    They've added some wierd << foo >> syntax that I didn't even bother to read about as I was in syntax shock.

    They've added ^ which indicates that a variable in a block is actually a parameter and therefore the blocks is actually a parameterized blocks (ie. anonymous function). So, now you can't tell if something surrounded by { }'s is just a block of code or whether it's an anonymous function. Although, I don't think this is a problem as it's usually obvious from the context.

    And I didn't even read to the end of the paper!

    Makes me want to go write some Lisp, which is perhaps the antithesis of Perl. Lisp has the maximum possibile flexibility through having the minimum possible syntax. Perl originally had little flexibility, now they are trying to add more by adding more syntax. The problem is, if they want to get anywhere near Lisp-level flexibility with this method they'll need to move to Unicode for the syntax!

    Justin Dubs

    1. Re:Holy syntax overload batman! by ajs · · Score: 4, Insightful

      if they want to get anywhere near Lisp-level flexibility with this method they'll need to move to Unicode for the syntax!

      Ok, first off... Perl 6 will use Unicode by default, of course, and yes there is some talk of using things like the dot-product symbol to mean roughly what you would expect it to mean. However, that is limited by the practicality of entering and viewing Unicode characters with modern equipment. Perhaps in another 10 years....

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

      You already had the $,@,%,& to prefix variables with.

      But in Perl 6, they are rationalized a great deal, and made simpler to use (e.g. Perl used to use the glyph to indicate the type of operation being performed on a variable, no the type of the variable. In Perl 6, that has been changed to reflect what most programmers expect, so @foo[0] is the correct notation for accessing the zeroth element of an array, not Perl 5's $foo[0]).

      Perl 6 is going ot be hard for outsiders to jump into at this stage because it doesn't exist yet. If you're not steeped in the culture of Perl 6's design, you won't be able to see where it's going, so everything looks kind of scary.

      However, in about 10 years, I expect Perl 6 to be seen as the starting point of a new kind of programming and a level of symbolic abstraction that allows us to start looking at code in a much more constructive way.

    2. Re:Holy syntax overload batman! by ajs · · Score: 4, Informative

      Much of Lisp's flexibility comes from having programs represented in the same form as data (S-expressions)

      That's the part that Perl does not have, and never will (though Perl 6 comes as close as a truely compiled language reasonably can). However, most Lisp code really doesn't benefit from this fact as much as it does from its side effects.

      Let me give you an example. One side effect of what you describe is lambda functions, and a cool feature distinguishes lambda functions from simple function pointers in C is closures.

      Perl provides the equivalent of Lambda functions in the form of anonymous subroutines, and they are also closures.

      So, while you are correct that much of the flexibility of lisp falls out of S-expressions, it's not true that you cannot have that flexibility WITHOUT S-expressions.

      What Lisp *does* have that Perl 5 does not is an excellent macro mechanism (which also falls out of S-expressions).

      That is probably the one major thing that Perl 6 will need in order to truely surpass Lisp's flexibility for general purpose tasks, and while it has been much discussed on the mailing lists, it won't be realistic to decide on it, and nail it down fully for a few itterations of the apocolypses. But it's certainly clear that Perl needs some form of macro system that is at least very nearly as flexible as Lisp's.

      Perl's eval is a red-herring. It's really a totally different (pair of) functions from Lisp's eval, acting as either parser or exception-handler. Lisp's eval is much more comparable to Perl 5's ->() operator which dereferences and executes a code reference which can be a reference to an anonymous or named closure, a subroutine or a regular method.

      You can also build CVs, which are just data-structures, in C and present them to Perl as a code reference. That does give you all of the power of Lisp, but you have to drop down to C to do it, so it isn't at all trivial or useful for routine use.

  9. Re:Release on the long road to nowhere by keesh · · Score: 4, Funny
    This guy is not trolling
    Erm, yes I was...
  10. 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?

  11. There's more than one way to do it? by MoxFulder · · Score: 5, Funny

    Perhaps the Perl motto should be changed from TMTOWTDI to TAMODVPCWDSSAAMSTWDI:

    "There's a multitude of different visually pleasing constructions with deceptively subtle syntax and auto-magical semantics that will do it."

    Okay, I love Perl 5... Perl 6 looks really cool but overwhelming. I'm glad they're adding the options for stricter type-checking and such, but remembering the syntactic shortcuts is gonna be even harder. I don't even want to know what the parser code looks like...

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

  13. Re:Perl 6 \not\in Perl ? by chromatic · · Score: 5, Informative

    It's not just you, but about 80% of the syntax stays the same. Much of the rest requires a few parser rule overrides. See ... And Now For Something Completely Similar, also by Damian.

    Backwards compatibility is a huge concern. That's why Ponie exists and why Dan's so careful about supporting Perl 5 semantics on Parrot. (As well, I expect 80% of the core Perl 5 tests will port to Perl 6 with surprisingly little work.)

  14. Re:For those who don't know.... by n1vux · · Score: 4, Informative
    In addition to the Apocalypses and Exegeses, Damian and Allison have produced two
    • Synopses, which are shorter and quicker to market.

    The names are a running gag on church-latin, that interconnects Larry's linguisticism, Damian's eclecticism, and the monastic themery of the Perl Monks' alternate retroynm for .PM. Larry's Apocalypses are not apocalyptic in the common figurative sense (although the neo-Luddites who think the only improvement on Perl5 is PHP or Python may think so), but are the Revelations of the gur, which is the original sense of the word, before it came to be used to refer to the particularly apocalyptic content of St.John's Revelations also called Apocalypse in the latin. The churchly Exegeses are non-canonical explanations of the deeper meanings of the canonical texts. And of course, synopses are shorter summaries, like Cliff Notes (TM) or Master-Plots (TM), and were originally applied to religious writings of course.

    require sig 1.3;
  15. 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.
  16. Re:Perl 6 \not\in Perl ? by chromatic · · Score: 4, Informative

    Would that everyone were so blind!

    • I have had code in Parrot for years. I have commit access.
    • I've taken hundreds of kilobytes of notes during Perl 6 design meetings.
    • I read the Apocalypses, Synopses, and Exegeses as they're being written and revised, weeks and months before they're released.
    • I helped quadruple the number of tests in the core test suite between Perl 5.6 and Perl 5.8.

    I think I have a pretty good sense of Perl 5, Perl 6, and Parrot.

    I also know how many Perl Foundation dollars have been spent to get Parrot where it is today. It might be enough to hire one of the top .NET folks for most of a year. For the money, Parrot's a bargain.

  17. Perl 6 is a pantheon... by LoveMe2Times · · Score: 4, Insightful

    I see Perl 6 as kind of a pantheon of programming gurus, and you can subscribe to whichever you like (or tell them all to screw off). The most important thing about Perl 6 is you can use whatever programming style suits you best. In a corporate environment, that style can even be dictated down by the powers that be, too. If you're one of those people that thinks that Lisp (et all) is (or is not) understandable, or thinks Java is a brain-dead C++, or that C++ is error prone Java, then Perl 6 may not be for you. You let (percieved) flaws obscure the important benefits, and as a result you miss out. Objectively, you would be examining the trade off between learning curve and increased efficiency over the time period of the project. In many cases, it is in fact better to stick with the tool you know, even if a different tool would be twice as effecient. Since it's just not possible to learn every single tool available, as professionals, we have to pick the most effective set of tools that we care to know given our interests and other expertise. This brings us around to the great thing about Perl 6: in one cohesive, sensible framework, it gives you really broad coverage. You don't have to learn it all at once--you start out using Perl 6 like Perl 5; then when you decide you want to do some lispy type things, you don't have to learn Lisp and a whole new toolchain, you can learn to do lispy types things in Perl. If you want to do things that would be well suited for C++ templates, you can learn the Perl 6 mechanisms for it instead of undertaking C++. And what is really, amazingly cool is that Perl 6 is shaping up to be a cohesive, well considered framework; it's not a jumble of competing ideas that don't play nicely with each other.

    If you've worked with C++ templates and metaprogramming, then you certainly understand the benefits being offered by a lot of the Perl 6 constructs. But the Perl 6 way is much more comprehensive, direct, clear, and intentional. Everything with blocks, anonymous subs, closures, multi methods, named parameters, operator overloading, and macors offers unbelievable oportunities for meta-programming. Once Perl 6 gets rolling and starts developing its own equivalent of Boost, then programming will never be the same. Boost changed everything already, but you've probably never heard of it; but Perl 6 will have mainstream appeal, acceptance, and use that Boost will never have.