Book Reviews
Practical Common Lisp by Peter Seibel
ISBN-13:
978-1590592397
Publisher:
Apress
Pages:
500
Since its publication a year ago this book has become a modern classic and the generally recommend introductory text on Common Lisp. I bought the book out of two reasons. First, my sheer curiosity about Lisp. What's so good about it? Does a nearly 50 year old language still have something others don't? Second, I wanted to know how web-programming is done in Common Lisp. Practical Common Lisp proved to be the right choice for answering these questions.
After an enjoyable introduction to the philosophy of Lisp and its history, Peter takes us through the classic "Hello, World" example in Common Lisp. Although the code up to this point is trivial, the chapter serves well as an introduction to the development environment (Emacs + SLIME) used throughout the book. It then kicks off answering my initial questions about Lisp's greatness by implementing a simple database. Peter explains different parts of Lisp as he needs them. It works surprisingly well and this is where I start to get really impressed by Lisp. Lisp allows for very expressive code and then there are the amazing macros too. Lisp macro system (not to be confused with C macros, which is an entirely different beast) is what sets it apart from other languages. Basically, the macro system is an embedded code generator. Peter introduces macros as a way of providing an SQL-like API to the database. In fact, solving problems by developing such a domain specific language is a typically Lispy way.
Following this jump-start, the book slows down and takes a more traditional approach by introducing the different features of Common Lisp one by one. Functions, variables, collections such as vectors and hash tables, and of course lists. Much ground is covered in these chapters. What impressed me most, besides the macros, is Common Lisp's condition system. This is exactly the kind of system I always wanted for error handling - I just didn't know it before! What's so magical about it? Well, let me compare it with exceptions in languages like C++ or Java. There the code that detects an error almost never knows the surrounding context. That's fine and exceptions allow us to delegate the error handling to higher layers. Now, that higher layer catching the exception knows the context. That is, it knows how to respond appropriately to the error. The problem is that even though it knows what to do it typically doesn't know how to do it; that information was where the error was detected and has been lost as the stack got unrolled. Conditions solve this problem by letting the code signaling an error (i.e. condition) also specify different strategies for recovering, so-called restarts. Higher layers may choose one of these restarts and continue execution from that point.
The descriptions are generally very good. However, learning a new language is hard and requires practice. Most introductory books recognize this by including exercises at the end of each chapter. Practical Common Lisp doesn't with the motivation that the practical chapters in the book cover this ground. I don't agree and found it necessary to go back and re-read chapters (I normally don't need that and I read quite a lot) in order to remember details. Exercises would definitely have helped to ease the pain.
Now, what about the practical parts? I really enjoyed the object-oriented framework for reading and writing binary data. After that my second wish came true: learning how to do web-programming with Common Lisp. Peter once again illustrates how powerful Lisp macros really are and how much repetitive code they help us get rid of. I was surprised to see how heavy use of the Common Lisp Object System Peter makes. Especially since Lisp gurus like Paul Graham deem it unnecessary. What I missed is mainly the evolutionary approach to program development at which Lisp is particularly well suited. Chapter 9 develops a unit-test framework using this style, but later chapters unfortunately lack it.
To conclude this review, if you're interested in Common Lisp, this book is a great start! Sure, it's clearly not for newcomers to programming, but for experienced programmers this only makes it more interesting as it keeps a high pace. The practical examples are excellent with respect to marketing the language and raising the interest in Lisp.
Reviewed May 2006