Oakland.pm

Reviews

Review of "Perl 6 Essentials"

by Allison Randal, Dan Sugalski, Leopold Tötsch

reviewed by George Woolley


Note

Recommendation

A very good book.

Perl 6 is not here yet. Even the definition of the language is still in flux. But many things are reasonably clear.

If you are big into Perl or for some other reason wish to explore this developing technology, this is the book for you. It's an exciting, well conceived book. You'll be exposed to the major aspects of Perl 6; and you'll also learn what you need to know to go further, to follow the on-going development, and to get involved (if you wish).

For a deeper examination, see my detailed review.

George Woolley, Oakland.pm

Quote from Larry Wall

"The essence of Perl is really context sensitivity, not just to syntactic context, but also to semantic, pragmatic, and cultural context. This overall philosophy is not going to change in Perl 6, ..." -- from Apocalypse 1

[top]

Chapter Titles

  • 1. Project Overview
  • 2. Project Development
  • 3. Design Philosophy
  • 4. Syntax
  • 5. Parrot Internals
  • 6. Parrot Assembly Language
  • 7. The Intermediate Code Compiler

Note

Basic Flow

  • Perl 6 source code
  • <Perl 6 Parser>
  • Abstract Syntax Tree (AST)
  • <Compiler>
  • bytecode
  • <Optimizer>
  • bytecode (optimized)
  • <Interpreter>

Notes

  • This shows the flow for a simple Perl 6 compilation and run.
  • <...> indicates ... is a module.
  • The input for a module is indicated on the preceding line and the output on the following line.

[top]


Some Relevant Links

Humor:

Some Google Searches

  • site:cpan.org "Perl 6"
  • inurl:perl6 OO
  • intitle:Parrot "Leon Brocard"

Notes

  • These are just some Google searches that worked out well for me.
  • But you have different interests, etc.
  • Still, they may suggest something.

Notes

  • Click on image above to go to Google.
  • Or if you wish, take a look at my Google Hacks Review.
  • Google rocks.

[top]


Request for Feedback

Let me know at george in the domain of metaart.org if you feel that:

  • I am wrong in general or in particular.
  • Something is poorly stated.
  • etc.

Thanks in advance for caring enough to comment. Acknowledgments, etc. are also appreciated.

Acknowledgement

Thanks to Edwin S of Oakland.pm who reviewed a late draft of this review and asked many penetrating questions.

[top]

Contents

Notes

  • My initial reading of this book was on-line using Safari. I didn't have a hard copy of this book until after I had completed the first full draft of this review.
  • For info on Safari, click on the image above.
  • I've been using Safari since February and have found it easy to use and quite useful. If you wish, take a look at my Safari Review.
  • For a special offer for O'Reilly user group members, click here.

[top]

The Title

I've found that O'Reilly titles do a good job of conveying what to expect in a book. So let's examine the terms in the title.

What's Perl 6? I'll assume that you are familiar with Perl.

Perl 6 is:

  • the next version of Perl
  • being worked on right now
  • a complete rewrite of Perl
  • syntactically different from Perl 5
  • a paradigm shift

paradigm shift: There are a number of radical shifts in the movement from Perl 5 to Perl 6. Here's two:

  • Perl 6 is the Perl community's rewrite of Perl.
  • Perl 6 uses a language neutral interpreter (called Parrot), opening up all sorts of interesting possibilities.

Here's a quote regarding the first. "The way I look at it, Perl 5 was a composition largely by a single composer - me. It's a fine classical composition, but in essence it's one person's view of how to make music. If you work with Perl 5 you have to follow the score pretty closely. Perl 6 is going to be designed by the community. We're going to be doing some jamming."
-- Larry Wall in the 2000 State of the Onion

Essentials? From what I understand, O'Reilly Essentials books:

  • have Essentials as the last word of the title
  • are early looks at fast evolving subjects
  • are not definitive
  • will likely be replaced by something more definitive at a later time
  • in the meantime, will help you evaluate the technology

How does the title fit the book? It fits well.

The book is indeed about Perl 6. It's also, necessarily, about Parrot, since Parrot, though language neutral, is the interpreter for Perl.

And the book is indeed an Essentials book in the O'Reilly sense. It does give us an early look at Perl 6, but it's certainly not definitive. The authors are careful to say what they think is stable and what they think is likely to change. There's enough laid out that you can likely do a tentative evaluation of Perl 6 relative to your specific concerns.

[top]

About the Reviewer

Background: I have some relevant background which helps me in reviewing this book, including:

  • I've been using Perl since 1994.
  • I've made significant use of over 20 different computer languages.
  • including coding in several different assembler languages.
  • For a while, I worked for a company that specialized in compiler development. I've done some compiler development. And I created a simple metacompiler that worked for fun.
Limitations: Some limitations I have in reviewing this book are:

  • I'm a supporter of O'Reilly.
  • I'm an advocate of Perl.
  • I'm not a language or a compiler expert. Nor am I a Perl expert.
  • I have no inside knowledge concerning the Perl 6 development.

[top]

The Why of it All

OK, here we go.

Why Perl 6? Well some parts of the language are showing their age and getting unwieldy -- like regular expressions. Hey, people are making fun of all our special characters, and sometimes they have a point. And the internals are getting hard to maintain and extend. If we want the flexibility to grow with ease in the future (and we certainly do), we need a revised syntax and a new internal engine.

And the people in the Perl community need something to be inspired by. Perl 6 is it.

What's so good about Parrot? OK, but we could have just redesigned the language and rewritten the internals. Right?

Possibly. But there are big advantages with Parrot such as:

  • We an use Parrot for both Perl 5 and Perl 6. And others can use Parrot to implement Ruby and Python and such.
  • And then features that people like can move more easily between languages.
  • And interoperability becomes far easier.

Parrot is kool.

Design Philosophy: There's a whole chapter on "Design Philosophy" [chapter 3]. A number of principles governing the Perl 6 design are explained there including:

  • 12 principles of natural language (that also apply to Perl)
  • a number of overall architectural principles

The fundamental design philosophy hasn't changed. Perl is just growing up, refining its act in some areas and flexing it's muscles in others.

One of the architectural considerations put forward is that "Perl Should Stay Perl" which includes:

  • making "easy things easy and the hard things possible"
  • Perl 6 being familiar to Perl 5 users
  • having a mechanism for translating Perl 5 to Perl 6

Perl has always tried to take into account relevant natural language principles so there's continuity there too.

The changes being made for Perl 6 are aimed at the flexibility, stability, and long term usability of the language.

[top]

The Language

There's a whole chapter on the syntax of Perl 6 [chapter 4] which has sections on:

  • Variables
  • Operators
  • Control Structures
  • Subroutines
  • Classes and Objects
  • Grammars and Rules

I'd read a little about Perl 6 before I read this book, but much of the material in this chapter was new to me. I found it relatively easy to absorb and fascinating.

I'll talk a little about just two of the many language changes.

Switches: In Perl 5, there's no switch statement for handling cases, so I often write things in the following pattern (where what the ... and ..... are is left to your imagination):

      if    ( ... ) { ..... }
      elsif ( ... ) { ..... }
      elsif ( ... ) { ..... }
      .....
      else          { ..... }

I'm aware of various other solutions, but this is, in fact, what I usually do.

In Perl 6, there is to be a switch statement and a natural way to indicate cases. I'll likely start using that and write things in something like the following pattern:

      given $topic {
         when ... { ..... }
         when ... { ..... }
         .....
         default  { ..... }
      } 

given in this pattern is a topicalizer, that is, if elsewhere in this pattern you make an explicit or implicit reference to $_, you'll be referring to $topic (or whatever came after given).

You may be wondering why the keywords used aren't switch and case rather than given and when. By the time you get to the point in the book talking about switches you'll know where to look for such answers.

Here's something abstracted from some Perl 5 code I wrote:

      if    ( $kind eq "RULE" ) { ..... }
      elsif ( $kind eq "ALT" )  { ..... }
      elsif ( $kind eq "TEXT" ) { ..... }
      .....
      else                      { ..... } 

In Perl 6, I'd likely write something like:

      given $kind {
         when "RULE" { ..... }
         when "ALT"  { ..... }
         when "TEXT" { ..... }
         .....
         default     { ..... } 
      }

To my mind, that's a much clearer expression.

Anyway, that's a somewhat simplified view of what I learned from the book about switches in Perl 6.

Rules:

Historically, Perl has had the richest implementation of regexes of any language. And regexes are better integrated into Perl than into any other language. However, the notation used violates basic language principles in numerous ways and is not well suited for writing whole grammars.

In Perl 6, we have rules (rather than regular expressions). And the notation for these rules:

  • takes much better account of language considerations
  • significantly improves integration with the rest of the language
  • and makes it possible to conveniently implement whole grammars

Rules in Perl 6 do not have the same syntax as regexes in Perl 5. Well, if you really want them to, there is a rule modifier that allows you to specify that a pattern uses Perl 5 regex syntax. My guess is you won't want to do this. Perl 6 rules are both more readable and more powerful than Perl 5 regexes.

What do the language changes mean to you? Well, how do I know? It depends on what you do, how you like to do it, etc. But I'll bet you find some things to be enthused by in this chapter.

To me, the language changes are like a dream about to come true. :)

[top]

Major Components of the System

Modules: Perl 6 uses Parrot for it's internals. Running a Perl 6 program involves four major modules:

  • Perl 6 Parser
  • Parrot Compiler
  • Parrot Optimizer
  • Parrot Interpreter

The Perl 6 Parser produces an Abstract Syntax Tree (AST) from Perl 6 source code. The Parrot Compiler produces bytecode from AST. (It also does some simple optimization.) The Parrot Optimizer produces optimized bytecode from bytecode. (It is an optional step in the process.) The Parrot Interpreter runs the bytecode. (In some cases, it may need to call the Perl 6 Parser to do its job.)

Parrot: Parrot consists of:

  • Parrot Parser
  • Parrot Compiler
  • Parrot Optimizer
  • Parrot Interpreter

The Parrot Parser is a general-purpose parser which can be used for different languages. Another option is to replace the parser with a parser tailored to the language which produces an AST. The replacement parser, for example, might be an already existing parser for the language.

[Chapter 5 of the book describes the functionality of Parrot with an emphasis on the Interpreter.]

Two Programs: The Parrot Assembler, assemble.pl, assembles bytecode from Parrot assembler code. [Chapter 6 describes the Parrot Assembler and the assembler language it is designed to process.]

The Intermediate Code Compiler (IMCC), imcc, is a highly flexible program which, among other things:

  • can take as input either assembler code or a special intermediate code produced by a parser
  • can optimize code
  • has the interpreter embedded in it

[Chapter 7 describes IMCC and the intermediate compiler code that it can handle.]

What happens to my Perl 5 code? This is an especially relevant question since Perl 6 is syntactically different from Perl 5.

There are two things that address this that I know of:

  • There's a Perl 5 to Perl 6 translator planned. [chapter 3] Though I gather there is no illusion that it will be 100% successful.
  • After the book was published, a new project called Ponie was initiated. Ponie stands for Perl (Perl 5, that is) on New Internal Engine (Parrot, that is). So, you should be able to run your Perl 5 code on Parrot.

And, of course, you could continue to run your Perl 5 progams exactly as you do now. :(

[top]

What's next?

How does one learn more? Well, on the web mostly. And the material you'll be reading in the book will help you prepare for that by giving you the basics of:

  • the underlying motivation of the Perl 6 project [chapters 1 & 3]
  • the history and structure and workings of the project [chapters 1 & 2]
  • the language changes [chapter 4]
  • the new compilation and interpretation environment [chapters 5-7]

And according to the Preface of the book, there will be a revised edition of the book each year until Perl 6.0.0 is released.

How does one get involved? From reading the book, I gather that the simplest way to get involved is:

  • join a mailing list
  • watch the traffic regularly
  • get a good sense of what is going on

After you've done these things, then when you have an insight, make a post to the list.

As a result of reading the book, I joined the perl6-internals list. I just joined it, and I'm still in the watch the traffic stage.

[top]

What I'd like different

Well, I think this is a very good first Essentials book. Still, it seems I always find something I'd like different.

I had difficulty understanding just what components were being referred to in the overview of the Parrot architecture [in Chapter 5] and their relation to the Parrot Assembler and to IMCC [which are described in Chapters 6 & 7]. I wish this was all made inescapably clear.

That's my list of things I wish were different in the book. Just one item on it.

Oh, I do also wish that Perl 6 was already released. That's not about the book. But this is a very ambitious effort, and I keep wondering: "When will Perl 6.0.0 be released?"

[top]

Who's the Book for?

Likely you, if you've read this far.

I would think the people who would most likely benefit from this book are:

  • Perl programmers, especially Perl advocates and supporters, who want to get a better handle on what Perl 6 will be like [chapters 1-4]
  • hackers (in the good sense) who want be involved in the development of Perl 6 [all 7 chapters]
  • programmers who are interested in exploring the innovative language independent interpreter approach that Parrot represents, for whatever reason [chapters 5-7]

The book has some suggestions on this too. [preface]

[top]

Note

  • Click on image to see catalog entry.

version 1.0.0 completed: 2003-07-23

Last Updated: 2003-07-24