
jeff_duntemann commented "Lisp ties my head in knots", so I thought I'd help him out. The Aha! moment for me with Lisp came from seeing the association with
Abstract Syntax Trees, which are a language compiler's internal representation of a line of code. Consider, for example, the quadratic equation, which can be expressed in Pascal syntax as (-b + sqrt(b*b - 4*a*c))/(2*a), where sqrt() is the square root function and * is the multiplication operator. (Note that this deliberately misses out the plus-or-minus part; I'll get to that later.) If you feed this into a compiler, what you get looks a bit like my illustration at right: a tree of operations, rearranged so that each operator has its operands as branches. If you were to convert an AST like this into text, using parentheses to show the tree structure, it would look like this:
(÷ (± (- 0 b) (√ (- (× b b) (× 4 a c)))) (× 2 a))Lisp is, in essence, the textual form. The syntax is different - it doesn't use × and ÷ because it started in the 1950s with typewriter terminals, just like Fortran, but the differences are trivial. It takes some concentration to see how we get from the diagram to the Lisp form, but it makes sense. And once you have that sorted out, whole new vistas open up.
One significant step is the idea that you can define functions that operate on code as if it were data. I could write a function called expand-plus-minus, for example, that took a list like the above and turned it into two lists, one with a plus in place of the ±, and the other with a minus. Thus, without knowing anything about the quadratic equation, my function can create two new pieces of code. Compiling and interpreting blur into irrelevance, and it becomes a genuinely powerful tool.
That's really the key to Lisp. It's what makes the Lots of Irritating Superfluous Parentheses necessary and valuable, rather than irritating. Any time anyone refers to Lisp as
like oatmeal with fingernail clippings, or asks me "
how can you read it with all those parentheses?", I have to agree with whoever it was who replied by opening up a book, pointing to a page and asking, "How can you read the words in among all those spaces?"