Overview: This is the Lisp Introduction Page. Refer to various Lisp materials online through the calendar page, or at the links below:
Lisp: Lisp is a fullfeatured programming language that has traditionally supported AI applications. In fact, AI courses are often taught using Lisp, although this is done less often now (too difficult to teach enough Lisp to be useful). Lisp is the oldest programming language still actively used. Some Lisp systems come with a complete development environment, and Lisp has been used for large software projects (such as Macsyma) and as the basis for software engineering. Lisp appears simple, but this is deceptive. Lisp is an interpreted language, and as such it has flexibility and power not available to traditional compiled languages such as C, C++, or Java. In Lisp more decisions are made at runtime. In exchange for this flexibility and power, Lisp execution has always been much slower than the traditional languages. Modern Lisp systems have a compiler that improves performance considerably, though not to the level of traditional languages. Lisp presents editing problems, particularly the large number of parentheses. Special lisp editors (or EMACS configured for Lisp) can help a lot, but we'll be doing small enough programs that we can ignore this. If you can, you should use an editor that matches parentheses for you.
The Lisp We Will Use: In this course, we will mostly study a subset that can be called "pure Lisp", just the basics. Lisp has the equivalent of ordinary loops, but you will not be allowed to use such loops in this course, because I want you to study recursion and a "functional programming style." This means in part the use of parameters, functions, and recursion, without using assignments or loops. We will only be using assignments (the function setq) at the top level. A dialect of Lisp called Scheme is often used in courses, but you are not to use it in this course. Scheme is a "stripped down" and "cleaned up" small version of Lisp. However, Scheme has a number of significant differences from Common Lisp. Socalled Common Lisp was created to combine most of the features in use by the various Lisp dialects. Common Lisp has a very large number of features, including many alternative ways to do the same thing. Common Lisp even includes classes and objectoriented programming. In this course we will use Common Lisp, but restricted to a small collection of permitted features. I expect you to use the notation and functions presented here, and not the various alternatives. (This is partly to force you to write the functions yourself, rather than finding them online.) Several faculty members know Lisp better than I do, but you are not to ask them to help you with assignments and other problems.
Lisp, Access and References:
Using Lisp: Lisp behaves in ways similar to some of the "scripting" languages and others. When you type the command "clisp", the Lisp interpreter gives you a prompt and processes further commands, one after the other. As with some scripting languages, Lisp does not require a declaration for a variable, and a given variable can be used for different data types in the same program. Here is a sample Lisp session, where material in red boldface (with comments in orange) is what you type in. The rest is what the system responds with. The system puts in bracketed input line numbers, but I'm usually going to leave them off in examples, because I want to cut and paste and edit these examples. 


The Power of Lisp: As mentioned above, Common Lisp, and this particular implementation (clisp), are extremely powerful. Lisp includes almost any feature you can imagine in a programming language: arrays. vectors, strings, macros, packages, hash tables, structures, and even classes that fully support OO programming with multiple inheritance. In addition to the normal data types, this Lisp has:
The first example above shows 50! calculated, all 65 digits. The second example evaluates a famous expression that is extremely close to an integer:
The third example considers the following series, known as Gregory's series
This series is similar to the harmonic series that you studied in calculus, along with the alternating harmonic series:
Gregory's series also converges very slowly. In fact, for each additional digit of accuracy in the computation of π, you need to sum ten times as many terms. The computations above use a Lisp function g that computes the sum of n terms of the series for n = 10^{3}, 10^{6}, 10^{7}. These calculations were carried out with roughly 90digit accuracy (with more for the last one). The digits that are equal to the digits of π are given in blue, while incorrect digits are given in red. (Single isolated digits might agree with probability 0.1, and most of these have been left red.) You can see that the value of the sum of 10 ^ i terms has an error in the ith decimal place (off by 1). But the table shows an astonishing number of other digits are equal to the corresponding digit of π, even though the numbers themselves are very poor approximations to π. Can you imagine what is happening here? I also performed all these calculations in Mathematica and got exactly the same answers. (There results are an artifact of using a power of 10 as the number of terms. The last line gives the sum of 9876543 terms of the series, and only a few early digits of it agree with π.)
It is rare for a software package to provide transcendental functions of arbitrary precision floating point numbers. I also performed most of these calculations in Mathematica and got exactly the same answers. For the Lisp function g above, I originally wrote a recursive version (as I expect students to do), but that version ran out of stack space when trying to add up 10^4 terms. The nonrecursive version above had no problem with 10^7 terms at roughly 100 digits, which took 2 minutes on my (slow) PC workstation.
Revision date: 20131026. (Please use ISO 8601, the International Standard Date and Time Notation.) 