I lied when I said I'd completed Chapter 5 of Lisp In Small Pieces. I went back and re-read it, and realized that I was going to have to do the exercises in the chapter if I wanted to understand what was going on well enough to get through chapter 6.

Chapter 5 wasn't nearly as hard as I'd thought it was going to be. It also wasn't much fun. No new interpreter came out of it. Instead, what I got was the same interpreter, with yet another layer of indirection.

Quinnec is making a point in chapter 5. "If you're going to present at OOPSLA, you'll need to know how the big boys write." And the big boys write in Greek. The chapter is about "the meaning of a program," and turns the core switch statement into a quasi-readable "the meaning of this expresssion is the meaning of this expression when..." with pattern matching for conditionals, abstractions, and sequences. The meanings themselves become repetitious definitions of expression, environment, memory, and continuation.

Oh, yeah, did I mention that absolutely everything in this is in continuation-passing style? Madness. It made sense, when I did it, but it was painful to work through all those changes and make it all work.

There's a giggle where Quinnec explains that Greek is used because each letter becomes a shorthand for something: an addressing scheme, a naming scheme, a continuation, an expression, so it's possible to fit the entire language definition on one page, leaving you nine pages to explain whatever it is that's unique about your language. "Greek letters are used because most programming languages are limited to the ASCII character set."

Obviously, this book needs to be brought into the 21st century. We have unicode now. I was able to copy the Greek verbatim into my comments, e.g. f[y → z] = λx . if y = x then z else f(x) endif.  Note the lambda and the other unicode characters supposedly out of my reach. Not only are they accessible to me, I've permanently encoded them into my keyboard. (Had to use that Windows key for something, after all.)

Translating the Greek into Scheme, and then into Coffeescript, my target language, was fun. No, really. When it was finally working, it was kinda nifty to see that it did in fact work. You end up building these enormous function stacks of "meaning," at the bottom of which is the print command, which translates to "print what that all meant." At that moment, all the functions built up trigger in the right order, the AST order, and the result is delivered to your screen. It's big and ugly and weird, but it works.

Chapter six is about making that all go faster. But I needed a chapter 5 interpreter before I could begin.

It's been two weeks since I finished chapter 5. The start of the school year for my daughter, and other life matters, have intervened. I've also been head deep in learning something esoteric for work, so I'll have go back and review that.