New book about Common Lisp: Let Over Lambda
- From: Doug Hoyte <doug@xxxxxxxx>
- Date: Wed, 21 May 2008 14:17:46 -0700 (PDT)
My name is Doug Hoyte--long time reader, first time poster.
Although I have been studying lisp since I bought a copy of
Winston & Horn in 1999, I have more of a background in C, perl,
forth, and network security. I distribute some free software
programs at my website www.hcsw.org and also am an Nmap developer.
I have read every lisp book I've been able to get my hands on
but none have resonated as deeply with me as "On Lisp" by Paul
Graham. In my opinion, this is one of the most important books
in computer science. Lisp macros are not given nearly enough
research attention relative to their importance. I wish there
were more On Lisps. A year or two ago I decided that the surest
way to change this would be to build one myself so I wrote a
book about Common Lisp called "Let Over Lambda":
I personally consider Let Over Lambda to be an unofficial sequel
to On Lisp. At the same time, Let Over Lambda is about practical
programming techniques, not theory. While Graham's book will tell
you about the different types of macros, Let Over Lambda will
show you how and why to use them.
The first three chapters are available online (follow the
Table Of Contents link). Eventually the entire text will be
online but printed copies are available right now for $39.95USD
from my lulu.com store:
I'm appending the first Let Over Lambda press release,
--------LET OVER LAMBDA PRESS RELEASE---------
Announcing _Let_Over_Lambda_ by Doug Hoyte: http://letoverlambda.com
If you are looking for a dry coding manual that re-hashes common-sense
techniques in whatever langue du jour, this book is not for you. This
book is about pushing the boundaries of what we know about
While this book teaches useful macro skills that can help solve your
programming problems today and now, it has also been designed to be
entertaining and inspiring. If you have ever wondered what lisp or
programming itself is really about, this is the book you have been
Chapter 1 "Introduction": A short introduction and a section
outlining the "U-Language" (conventions and terminology).
Chapter 2: "Closures": Unlike the later chapters, this one contains no
original research. Instead, it is a from-the-ground-up description
of scope, extent, and closures. It is designed to fill any gaps in
knowledge about these constructs. This chapter describes everything
you need to effectively use closures in Common Lisp: How to reason
about them, similarities and differences between them and object
systems, how efficient they are, how they interact with dynamic
etc. This chapter introduces a terminology for closures I am so fond
of I named the book after: "Let Over Lambda".
Chapter 3: "Macro Basics": This chapter starts with a few simple but
interesting problems and shows natural metaprogramming techniques
for solving them. Macro programming slang can be difficult for the
un-initiated to follow but after reading this chapter you will
understand what is meant by "iterative development", "domain
language", "control structure", "free variable", and "variable
This chapter introduces an original notation for creating macros
gensyms: gensyms are indicated with special-case symbol print-names.
The classic lisp macro once-only is defined as a macro combination
using our new gensym macro.
Chapter 4: "Read Macros": Read macros are a difficult subject to
explain because most of the best ones are already included
with lisp and are no longer thought of as read macros but rather
integral parts of the language. Nevertheless, this chapter
introduces a few read macros that can make a big difference for
certain lisp programs. Different options for reading strings
(ones where you don't need to "escape" characters) are implemented.
A syntax for CL-PPCRE regular expressions that makes them just as
convenient as in perl is developed. Backquote and cyclic expressions
are also explained in depth. The final section describes best
practices for processing untrusted user input with Common Lisp.
Chapter 5: "Programs That Program": In a functional language if it
looks like a function call it is enforced by the syntax of the
language to be a function call. But lisp macros are the exact
opposite of that. This chapter shows how to construct and reason
about complex systems of lisp macros. By using a "top-down"
programming style, you can program however you feel like and then
later bend the language into compiling/interpreting those programs.
This is one of my favourite chapters because it shows that the
implication of lisp macros is that in lisp, nothing is impossible.
A macro is created that makes all "cxr" combinations available:
(with-all-cxrs #'caadadadddaaaddddadadar). This chapter also
explains macrolet and recursive macros.
Chapter 6: "Anaphoric Macros": This chapter is about anaphoric
macros as described in On Lisp. Such macros invisibly capture
variable references. Especially when combined with macros that
invisibly inject variable references, the anaphoric macro is a
topic so unexplored that I think entire original books are yet
be written about it. This chapter focuses on one such application:
Re-wiring lexical scope. Macros let you swap lambda forms at
run-time while preserving their closed over bindings or even
eval forms without throwing out your lexical environment:
(let ((x 1))
(let ((x 1))
... only one will do what is intended. This chapter also
includes a section on finite state machines and one that defines
a type of scoping that we have been using since chapter three
called sub-lexical scope. Symbol macros and their important
relationships with generalised variables are explained.
Chapter 7: "Macro Efficiency Topics": We usually don't care about
performance but when we do there is no better language for
experimenting with or actually implementing efficient programs
than lisp. If you know C or other low level languages, this
chapter will tell you everything you need to know in order to
transfer this knowledge to Common Lisp's machine code compilers.
There is a section "Getting To Know Your Disassembler" that
deciphers many common compiler notes and points out useful things
to look for in compiled lisp code. Macros are used to simulate
C pointers in two ways: a safe closure-based layer of syntax,
and coaxing the lisp compiler into creating unsafe machine
instructions. A simple heap overflow is demonstrated. Efficient
memory management with macros is described. Because there are
few good descriptions elsewhere, compiler macros are explored
in depth: what they are, how they are different from regular
macros, how to use them.
Batcher and Knuth's Algorithm 5.2.2M "merge-exchange sort" is
found to be useful as the basis for a re-implementation of Paul
Graham's sortf macro from On Lisp. Decimal order of magnitude
performance improvements over our Common Lisp implementation's
#'sort function are observed. There is a brief discussion of
sorting network theory and fast median calculations. The chapter
ends reminding you to take all benchmark results with a large
grain of salt.
Chapter 8: "Lisp Moving Forth Moving Lisp": One of my favourite
languages (after lisp of course) is Chuck Moore's forth. This
chapter is my attempt at explaining forth to a lisp audience.
Although stacks may be the most apparent feature of forth, forth
is about stacks no more than lisp is about lists. It is actually
"threading" (a way of assembling programs into memory) that makes
forth what it is. Just as the easiest way to write certain
programs in non-lisp languages is to first write a lisp interpreter
in that language, the same is true for forth. This chapter
develops a forth compiler in lisp and along the way defines the
central theme of the book--duality of syntax. After forth has
been bootstrapped, we use forth immediate words (like lisp macros)
to write lisp programs. The conclusion is that forth is great for
the same reason that lisp is great: it is a high local maximum in
the space of meta-programming languages.
There are also four appendices of highly opinionated flame-bait
for your (dis-)enjoyment.
The above is only a summary of some of the topics discussed in
Let Over Lambda. I have tried to aggregate a large amount of lisp
knowledge so a short summary cannot do the full content justice.
Read the first three chapters free online:
Or purchase a full copy from lulu.com:
Thanks for your interest,
President, CEO, Chief Lisp Officer
Lambda Press Department, HCSW
--------LET OVER LAMBDA PRESS RELEASE---------