Common Lisp - An Interactive Approach

Peter Kitson

ISBN : 0716782189

Order a printed copy of this book from Amazon.

Cover Design - Common Lisp - An Interactive Approach

For your free electronic copy of this book please verify the numbers below. 

(We need to do this to make sure you're a person and not a malicious script)



Sample Chapter From Common Lisp - An Interactive Approach
     Copyright © Stuart C. Shapiro

Teaching LISP

Lisp is the language of choice for work in artificial intelligence and in symbolic algebra. It is also important in the study of programming languages, because, since its inception over thirty years ago, it has had full recursion, the conditional expression, the equivalence of program and data structure, its own evaluator available to the programmer, and extensibility—the syntactic indistinguishability of programmer-defined functions and “built-in” operators. It is also the paradigm of “functional,” or “applicative,” programming. Because of the varied interests in Lisp, I have tried to present it in a general and neutral setting, rather than specifically in the context of any of the special fields in which it is used.

Above all, Lisp is an interactive language. A Lisp program is not built up from imperative statements, but from forms, each of which has a value. The Lisp programmer sits in front of a terminal, interacting with the Lisp listener. During such a session, a program gets written, read, tested, modified, and saved for future use. Most Lisp implementations provide more than just a programming language, they provide an entire environment including tracing, inspectors, debuggers, and other programmer aids, almost all written in Lisp itself.

I learned Lisp by experimenting with it, typing S-expressions and seeing what happened. That is the learning style I encourage in this book. Teaching Lisp by having the student sit down at a terminal and experiment right from the start influences the order of topics. For peace of mind, the first thing a novice needs to know about being in a new environment is how to get out. Therefore, Chapter 1 is concerned solely with getting into Lisp and getting back out. Lisp input is not tied to line boundaries, and extra spaces are ignored. Students need to experience this flexibility early so they do not feel they are under more constraints than they really are. A novice makes mistakes (and so do we all). Therefore, it is important to show the debugger and error messages early. Since typing errors will occur, backspace and delete keys are important, and the student should experience the entire character set. The general approach is to prepare the student for the unexpected. Since new concepts must be built on existing conceptual structures, numeric examples are used before symbolic examples.

Since the best language for defining Lisp is Lisp itself, many Lisp functions are introduced by having the student define them first. This means that some functions I have been tempted to discuss early have been put off until the student has enough background to define them.

I have written the exercises so that it is reasonable to expect the student to do all of them. Therefore the only long projects are those that are distributed throughout the text as exercises that have the student modify and extend functions that are saved on files.

Because I suspect that many students will have had experience with some imperative programming language, I teach pure Lisp before the imperative constructs. This forces the student away from the “Pascal with parentheses” style that I saw so much in the past. By the time I introduce imperative Lisp in Part III, the student should be used to the functional style of pure Lisp and should be able to develop a good, balanced programming style.