Cooking with Lisp

Another blog about Lisp, the world's greatest programming language.

Thursday, April 21, 2005

Take That, O'Reilly!

I just received my copy of Practical Common Lisp! About time, especially since I preordered it. Very nice hardcover, will be able to withstand rigourous hacking sessions :)

We knew that Peter Norvig was doing the blurb on the back, but on the inside cover, there's praise from a who's who in the Lisp world: Scott Fahlman, Philip Greenspun, John Foderaro, Christian Queinnec, and a few more. Pretty powerful endorsements.

Congratulations, Peter!

Monday, April 11, 2005

Doing My Part to Sell Practical Common Lisp

What can I say that others haven't said about Peter Seibel's new Practical Common Lisp?

It is now the best written introduction-to-intermediate Common Lisp book you can buy. It's great reading, the practical focus of the examples are well chosen and meaningful, and he jumps right in with the power of Lisp, instead of doing the pedagogically boring "this is a list" and "this is cons, car, and cdr".

I especially like the domain-specific language approach the book uses. In particular, Chapter 24 - Practical: Parsing Binary Files, and the later chapters are excellent examples of what you can really do with macros. In fact, I think Chapter 24 is standalone to point that, with some warning, you could show it to someone interested in the kind of power you get with macros, but doesn't want to wade through the whole book to get to the punchline. That person wouldn't understand a lot of the code, but would certainly see the ability of creating macros that can write a significant amount of straightforward boilerplate code.

I can't wait to get my copy.

Haskell and the Perl Community

I've spent the last 6 months heavily studying Haskell and the semantics of programming languages. Lurking on Lambda the Ultimate has been a great resource for this. Although I was really into functional programming in the early 80's when I was in college, I really didn't pay attention to the FP world since then. I was very impressed by the amount of progress the FP community has made in areas such as type inferencing and things like monads for i/o. I would say that they progress faster than any other programming language community. Haskell is a very interesting and powerful language and I encourage Lispers to take a serious look at it. It is now my 2nd favorite language.

Now, the reason I mention this is that something very interesting is happening between the Haskell and Perl communities. They are starting to cross-fertilize. I don't think you can imagine a more stranger pairing. This started in February, when Autrijus Tang started writing a Perl 6 compiler in Haskell. He started on February 1st and had the first version in 6 days!

Here's why he chose Haskell:
Many Perl 6 features have similar counterparts in Haskell: Perl 6 Rules corresponds closely to Parsec; lazy list evaluation is common in both languages; continuation support can be modeled with the ContT monad transformer, and so on. This greatly simplified the prototyping effort: the first working interpreter was released within the first week, and by the third week we have a full-fledged Test.pm module for unit testing.
A large portion of a Perl 6 compiler and interpreter was only 4,000 lines of Haskell. That's an incredible amount of productivity and expressive power.

You can follow Autrijus' blog to read the phenomenal daily progress.

Now, even more amazing, is that the project has drawn members from both the Perl and Haskell communities to contribute code. The Perl folks' new experience with Haskell is even feeding back into the Perl 6 design process.

I can't think of any other case where two different programming language cultures literally at the opposite sides of the universe have come together like this.

This interview with Autrijus is very interesting reading on how he got hooked up with Haskell, his experiences with it, and the cross-fertilization.

Perl 6 Now

Perl 6 Now - The Core Ideas Illustrated with Perl 5 is the second book that will be of interest to Lispers who need to use Perl. It talks about the features in the upcoming Perl 6 and shows how to use the various CPAN modules that implement most of those features today in Perl 5.

The last 4 chapters are particularly interesting, as they cover the new set operators (any and all), lexical closures, continuations, and coroutines.

One thing that I learned from this book that I wasn't aware of is that every {} block, no matter the context, will be a full, first-class closure. It's nice that Perl 6 will be supporting such a nice, lightweight syntax for that. Perl 6 is going to be a very interesting language, and Lispers and other functional programmers (like Haskellers and O'Camlers) will be well positioned to take advantage of these features.

I really appreciate that the Perl community is embracing the powerful ideas found in Lisp and Haskell, unlike the recent news from the Python community about starting to consider removing some of the "redundant" functional features.

Higher Order Perl

For those who regularly use Perl, you might be interested in two new books that show how to use Perl in more Lisp-ish ways.

The first is Higher-Order Perl, by Mark Jason Dominus. It's basically closures on steroids for Perl. Topics covered are recursion, iterators & generators, memoization, higher-order functions, combinator-style parsing ala Haskell, and domain-specific language generation. It is chock full of goodness.

Mark is a long-time Lisp and Haskell user and mentions influential books in his preface such as Norvig's PAIP ML for the Working Programmer, SICP, and Bird's Introduction to Functional Programming.

Here's what he has to say about Lisp in his preface:
Around 1993 I started reading books about Lisp, and I discovered something important: Perl is much more like LIsp than it is like C. If you pick up a good book about Lisp, there will be a section that describes Lisp's good features. For example, the book Paradigms of Artificial Intelligence Programming, by Peter Norvig, includes a section titled What Makes Lisp Different? that describes seven features of Lisp. Perl shares six of these features; C shares none of them. These are big, important features, features like first-class functions, dynamic access to the symbol table, and automatic storage management. Lisp programmers have been using these features since 1957. They know a lot about how to use these language features in powerful ways. If Perl programmers can find out the things that Lisp programmers already know, they will learn a lot of things that will make their Perl programming jobs easier.
You can read more about the book at this interview.