The introduction to Lisp follows. Additional information about this book, along with access to software, is available via http://www.ai.mit.edu/people/phw/Books/

Understanding Symbol Manipulation

This book is about Lisp, a programming language that takes its name from List Processing. The book has three parts, each written to accomplish a particular purpose: This brief chapter describes what symbol manipulation is all about, indicates why symbol manipulation is important, and explains why Lisp is the right symbol-manipulation language to learn.

Symbol Manipulation Is Like Working with Words and Sentences

Everything in a computer is a string of binary digits, ones and zeros, that everyone calls bits. From one perspective, sequences of bits can be interpreted as a code for ordinary decimal digits. But from another perspective, sequences of bits can be interpreted as a code for wordlike objects and sentencelike objects. A symbol-manipulation program uses symbolic expressions to remember and work with data and procedures, just as people use pencil, paper, and human language to remember and work with data and procedures. A symbol-manipulation program typically has procedures that recognize particular symbolic expressions, tear existing ones apart, and assemble new ones.

Two examples of symbolic expressions follow. The parentheses mark where lists begin and end. The first is a description of a structure built out of children's blocks. The second is a description of a certain university.


(arch (parts lintel post1 post2)
      (lintel must-be-supported-by post1)
      (lintel must-be-supported-by post2)
      (lintel a-kind-of wedge)
      (post1 a-kind-of brick)
      (post2 a-kind-of brick)
      (post1 must-not-touch post2)
      (post2 must-not-touch post1))
(mit (a-kind-of university)
     (location (cambridge massachusetts))
     (phone 253-1000)
     (schools (architecture
               business
               engineering
               humanities
               science))
     (founder (william barton rogers)))
Certainly these are not scary. Both just describe something according to some conventions about how to arrange symbols. Here is another example, this time expressing a rule for determining whether some animal is a carnivore:

(identify6
  ((? animal) has pointed teeth)
  ((? animal) has claws)
  ((? animal) has forward eyes)
  ((? animal) is a carnivore))
What we see is just another way of expressing the idea that an animal with pointed teeth, claws, and forward-pointing eyes is probably a carnivore. To use such a rule, a program must take it apart, determine if the patterns involving teeth, claws, and eyes are compatible with what is known about a particular animal in a database, and if they are compatible, add the conclusion that the animal is a carnivore to the database. All this is done by manipulating symbols.

LISP Helps Make Computers Intelligent

These days, there is a growing armamentarium of programs that exhibit what most people consider intelligent behavior. Nearly all of these intelligent programs, or seemingly intelligent programs, are written in Lisp. Many have great practical importance. Here are some examples: Consequently, people who want to know about computer intelligence need to understand Lisp.

LISP Promotes Productivity and Facilitates Education

Lisp is an important language even when computer intelligence is not involved. Here are some examples: Given all these examples, it is no surprise that the following is accepted by nearly everyone:

LISP Is the Right Symbol-Manipulation Language To Learn

There are too many programming languages. Fortunately, however, only a few are for symbol manipulation, and of these Lisp is the most used. After Lisp is understood, most of the other symbol-manipulation languages are easy to learn.

Why has Lisp become the most used language for symbol manipulation, and lately, much more? All of the following arguments have adherents:

Happily, Lisp is an easy language to learn. A few hours of study is enough to understand amazing programs. Previous exposure to some other programming language is not necessary. Indeed, such experience can be something of a handicap, for there can be a serious danger of developing a bad accent: other languages do things differently, and procedure-by-procedure translation leads to awkward constructions and poor programming practice.

One reason Lisp is easy to learn is that its syntax is extremely simple. Curiously, Lisp's present syntax has strange roots. John McCarthy, Lisp's inventor, originally used a sort of old Lisp, which is about as hard to read as old English. At one point, however, he wished to use Lisp to do a piece of mathematics that required both procedures and data to have the same syntactic form. The resulting form of Lisp quickly caught on.

COMMON LISP Is the Right LISP To Learn

The Lisp used throughout this book is CommonLisp. We use CommonLisp because it is modern, powerful, and widely available. CommonLisp also is the accepted standard for commercial use. Do not be confused by references to other, strangely-named Lisps. Most are either obsolete dialects or CommonLisp with company-specific extensions.

Lately, CommonLisp has been extended to include features for object-oriented programming via CLOS, the COMMON LISP Object System. Several chapters in this book explain how CLOS makes CommonLisp more powerful.

Beware of False Myths

There is no perfect computer language, and to be sure, Lisp has defects. Many of the original defects have been fixed, even though some people mistakenly cite them even today. Among the most pervasive and unfortunate myths are the following: In fact this was true at one time. This historical problem has been corrected by the development of good programs for translating the stuff programmers produce into the instructions that a computer can execute directly, without further decomposition. Said another way, the problem has been corrected by the development of good Lisp compilers. In fact this also was true at one time. In the old days, Lisp was used strictly in research, where interaction is at a premium and high speed for fully debugged application-oriented programs is less important. Today, however, excellent Lisp compilers have been developed to support the growing commercial demand for Lisp programs. Actually, this is not a myth. Some are. But that is only because Lisp makes it possible to create programs that are big enough to know a lot. A few years ago, getting started with Lisp required a million-dollar commitment. Today, on the low end, excellent Lisp systems for personal computers start at only a few hundred dollars, and on the high end, even the fanciest Lisp systems running on Lisp-oriented workstations cost well under a hundred thousand dollars. In fact the parentheses problem goes away as soon as you learn how to use a Lisp editing program that helps you put things down on an editing screen properly. No one finds the following to be particularly clear:

(defun fibonacci (n) (if (or (= n
0) (= n 1)) 1 (+ (fibonacci (-
n 1)) (fibonacci (- n 2)))))
But the equivalent, formatted version is fine after a little experience:

(defun fibonacci (n)
  (if (or (= n 0) (= n 1))
      1
      (+ (fibonacci (- n 1))
         (fibonacci (- n 2)))))
Lisp-oriented editors make it easy to produce the formatted version as it is written.
  • Myth: Lisp is hard to learn.
Lisp earned its bad reputation by being in the company of some hard-to-read books in its youth. Now there are many good ones, each with its own distinguishing features.

Highlights

  • Symbol manipulation is like working with words and sentences.
  • Lisp helps make computers intelligent.
  • Lisp promotes productivity and facilitates education.
  • Lisp is the right symbol-manipulation language to learn.
  • CommonLisp is the right Lisp to learn.
  • Beware of false myths. Lisp is an easy-to-learn, fast-running, productivity-multiplying language, well-suited to many applications both in and outside of Artificial Intelligence.