Perl 6’s Top 3 Coolest Features

Perl 6 has some really cool features. Features I’d like to use in production projects. But is Perl 6 suitable for production?

I keep hearing, no, because it’s unstable, the spec is still being hammered out, there are still too many bugs, it’s still too slow, the documentation lacks (or is just plain wrong), key features are still missing, it has insufficient module support.

But I have never been one who blindly accepts the evaluations of the crowd, because the crowd is often dominated by zealots twisted by hate and zealots twisted by love, and I’ve found a great beauty and symmetry in that nuance that lies in between zealotries.

Besides which, Perl 6 (hereinafter referred to as “P6”) includes a number of features that fit a particular real-world application that I happen to be thinking about. That’s another post. But several P6 features struck me. Here are the top three:

  1. “whatever” star (and other elegances) – In the historic spirit of Perl, P6 includes numerous operators and other features that increase the expressive power of the language, thereby making beautiful code possible. (And in the historic spirit of Perl, you will have to use your actual brain in order to make your code beautiful. If you don’t know how to express yourself in a natural language like English, you will probably also have trouble expressing yourself in a programming language like Perl.)

    These features are often hyped and sometimes seem kinda gimmicky to me and researchy and “Yeah, that’s très kewl, but why would I ever actually use it in real life?”… Except that, just playing with the language, I have already found a few instances in which I would like to actually use these features. I’d rather be more expressive, more beautiful, rather than coding up the equivalent using more verbose, less expressive language structures.

    The classic example is the “whatever” star, *, which is pronounced, “whatever,” and is translated, “whatever makes sense here.” So in P6, grep * %% 2, 1..10 finds all the numbers between 1 and 10 inclusive that are divisible by 2. (Because %% is the P6 “divisible by” operator.)

  2. grammars – P6 expands on Perl 5’s once revolutionary (now universal) regular expressions. While Perl 5 (and now practically every other language under the sun) parses regular expressions, by which your code can recognize the elements of simple strings, P6 now allows you to define complete lexicographies and grammars.

    In fact, P6 itself is defined as a Perl-6 grammar.

    P6 grammars should make simple templating systems easy. And should make possible full-blown domain-specific languages that interoperate seamlessly with your P6 code.

  3. lazy gather – This is my top, coolest P6 feature—if I understand it correctly.

    According to the P6 spec, rather than returning a list of results, you can instead provide code that tells how to construct the list, and return each result one by one. As your code runs, each result will be “gathered” into the list. And the language will run that code “lazily,” only as needed to construct the results actually needed.

    In principle, this means we should be able to create something that looks and acts very much like a partial continuation (if lazy gather is indeed lazy, synchronous, and deterministic). Such a construct would be very useful not only in the next generation of web frameworks, but in numerous other applications as well, any processing flow that is readily expressed as a state-machine.

Part of the challenge, of course, is that some (most?) of the Wow! is, at this time, still just hype. That goes without saying when dealing with a second-system like P6. The P6 spec defines so many kewl, often overlapping features, with precisely defined edges. The proliferation of such edges, in fact, may be part of the reason implementations have been plagued by persistent bugs and performance issues, and still are.

However, I don’t need an implementation of the full P6 spec. I don’t even need an implementation that’s as fast as Perl 5, or Java or PHP or Ruby or Python or any other language. I just need a subset of features that run well enough to make it worth my while to choose this platform to develop my app.

So in upcoming posts in this series, I’ll be exploring these features, running sample code, trying different P6 implementations, and looking at what parts of the language run well enough and fast enough to be considered potentially useful.


P.S. Click here to read the next part of the series.

This entry was posted in Uncategorized and tagged . Bookmark the permalink.

2 Responses to "Perl 6’s Top 3 Coolest Features"

Leave a reply