Chapter 1. Getting Started with Lisp

This chapter begins with an introduction to the various dia lects of Lisp. Then we’ll talk a bit about ANSI Common Lisp, the dialect that we’ll be using in this book. Finally, you’ll get started by installing and testing CLISP, the implementation of ANSI Common Lisp that will let you run all the Lisp games you’re going to be creating!

Lisp Dialects

Any language that obeys the central principles of Lisp is considered a Lisp dialect. Since these principles are so simple, it’s not surprising that literally hundreds of dialects of Lisp have been created. In fact, since so many budding Lispers create their own Lisp dialect as an exercise, there may be thousands of partially completed Lisps slumbering in long-abandoned directories on hard drives across the planet. However, the vast majority of the Lisp community uses two Lisps: ANSI Common Lisp (often abbreviated CL) and Scheme.

In this book, we’ll be talking exclusively about the ANSI Common Lisp dialect, the slightly more popular of the two. Nevertheless, most of the knowledge you’ll gain from reading this book will also be relevant to Scheme (although the names of functions tend to differ somewhat between the dialects).

A Tale of Two Lisps

Some deep philosophical differences exist between ANSI Common Lisp and Scheme, and they appeal to different programmer personalities. Once you learn more about Lisp languages, you can decide which dialect you prefer. There is no right or wrong choice.

To aid you in your decision, I have created the following personality test for you:

image with no caption

If you chose A, you like raw power in your language. You don’t mind if your language is a bit ugly, due to a lot of pragmatic compromises, as long as you can still write tight code. ANSI Common Lisp is the best language for you! ANSI Common Lisp traces its ancestry most directly from the ancient Lisp dialects, built on top of millions of programmer hours, giving it incredibly rich functionality. Sure, it has some baroque function names due to countless historical accidents, but this Lisp can really fly in the right hacker’s hands.

If you chose B, you like languages that are clean and elegant. You are more interested in fundamental programming problems and are happy to while away on a beautiful meadow, contemplating the beauty of your code, occasionally writing a research paper on theoretical computing problems. Scheme is the language for you! It was created in the mid-1970s by Guy L. Steele and Gerald Jay Sussman and involved some soul-searching about the ideal Lisp. Code in Scheme tends to be slightly more verbose, since Schemers care more about mathematical purity in their code than creating the shortest programs possible.

If you chose C, you’re someone who wants it all: the power of ANSI CL and the mathematical beauty of Scheme. At this time, no Lisp dialect completely fits the bill, but that could change in the future. One language that might work for you (although it is sacrilege to make this claim in a Lisp book) is Haskell. It is not considered a Lisp dialect, but its followers obey paradigms popular among Lispers, such as keeping the syntax uniform, supporting native lists, and relying heavily on higher-order functions. More important, it has an extreme mathematical rigor (even more so than Scheme) that allows it to hide very powerful functionality under a squeaky clean surface. It’s essentially a wolf in sheep’s clothing. Like Lisp, Haskell is a language that any programmer would benefit from investigating further.

Up-and-Coming Lisps

As just mentioned, there really isn’t a true Lisp dialect available yet that possesses both the power and flexibility of ANSI Common Lisp and the elegance of Scheme. However, some new contenders on the horizon may attain the best-of-both-worlds crown in the near future.

One new Lisp that is showing promise is Clojure, a dialect developed by Rich Hickey. Clojure is built on the Java platform, allowing it to leverage a lot of mature Java libraries right out of the box. Also, Clojure contains some clever and well-thought-out features to ease multithreaded programming, which makes it a useful tool for programming seemingly ubiquitous multicore CPUs.

Another interesting challenger is Arc. It is a true Lisp language being principally developed by Paul Graham, a well-known Lisper. Arc is still in an early stage of development, and opinion varies widely on how much of an improvement it is over other Lisps. Also, its development has been progressing at a glacially slow pace. It will be a while before anyone can say if Arc might be a meaningful contender.

We’ll be dipping our toes in some Arc and Clojure in the epilogue.

Lisp Dialects Used for Scripting

Some Lisp dialects are used for scripting, including these:

  • Emacs Lisp is used for scripting inside the popular (and overall awesome) Emacs text editor.

  • Guile Scheme is used as a scripting language in several open source applications.

  • Script-Fu Scheme is used with the GIMP image editor.

These dialects are forks from older versions of the main Lisp branches and are not typically used for creating stand-alone applications. However, they are still perfectly respectable dialects of Lisp.

ANSI Common Lisp

In 1981, in order to cope with the dizzying number of dialects of the language, members of the varying Lisp communities drafted a specification for a new dialect named Common Lisp. In 1986, this language, after further adjustments, was turned into the ANSI Common Lisp standard. Many of the developers of older versions of Lisp modified their interpreters and compilers to conform to this new standard, which became the most popular version of Lisp and remains so to this day.

Note

Throughout this book, the term Common Lisp refers to the version of Common Lisp defined by the ANSI standard.

A key design goal with Common Lisp was to create a multiparadigm language, meaning it includes support for many different styles of programming. You’ve probably heard of object-oriented programming, which can be done quite nicely in Common Lisp. Other programming styles you may not have heard of before include functional programming, generic programming, and domain-specific language programming. These are all well supported within Common Lisp. You’ll be learning about each of these styles, along with others, as we progress through this book.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.158.36