LISP ignores upper and lower case outside strings. White space is used to separate adjacent words and otherwise significant only inside strings. The meaning of aword is determined by their place in the input.
NIL is for False and the empty list (),
T is for True,
A list can be empty (NIL), an atom (word, number, string), a pair, or a list of lists between parentheses.
Lisp allows you to associate a value with an atom. You can then use that atom
in place of the value. Normally, this is done when a function is called: the
arguments are bound to the values of the actual parameters. You can also
change the values bound to an atom. We call such atoms variables:
For example: (QUOTE +) outputs
+, (+ ....) adds up the arguments, and + gives an "undefined value" error.
Defining New Functions
Functions are declared in two ways:
Both create a global meaning for the name and allow it to be used as an operator:
. . . . . . . . . ( end of section Syntax) <<Contents | End>>
. . . . . . . . . ( end of section Some Functions) <<Contents | End>>
|If value(e1) is||Not NIL||NIL|
|(COND (e1 e2 ) more) returns value of||e2||(COND more)|
. . . . . . . . . ( end of section Some Macros) <<Contents | End>>
(DEFINE (length L)
((NULL L) 0)
((ATOM L) 1)
( T (+ 1 (LENGTH (CDR L)) ))
The first LISP was defined by an interpreter - called EVALQUOTE. It used dynamic scoping with shallow binding and associated a "P-list"(Property List) with each atom. Nowadays LISPs (including Scheme) use static scoping but the P-Lists remains a useful tool.
In our LISP (XLISP) the
I added the
The LISP block structure:
Every LISP S_expression evaluates to one of a NIL, an atom, or a CONS-pair.
Thus it is useful to study how these kinds of things behave.
LISP is "logical" in the sense that its inventors had a set of well defined
assumptions (axioms) that they wanted LISP to implement. Here are some of
For all LISP expressions x,y:
If x is a Cons-pair then
No Cons-pair is also an atom:
No Cons-pair is NIL:
The above describe the simple behavior of CAR, CDR, CONS, NIL and so on.
The following are more complex and do not have to be mastered.
More Advanced Axioms
First we have an induction axiom that states that if a property(P) is
true of NIL and all atoms, and is preserved when new lists are constructed,
then it is true of all lists:
(induction): if P(NIL) and for all x(if (ATOM x) then P(x)) and for all x,y( if P(x) and P(y) then P(CONS x y) ) then for all x(P(x)).
The induction rule essentially limits lists to precisely those that can be constructed from NIL and the atoms.
The following recursion axiom permits us to reason about simple
recursive definitions. It states the circumstances when we
can conclude that two functions f and g are always equal.
(recursion): if for all x:atom( f(x) = g(x) ) and f(NIL)=g(NIL) and for some H, all x( (if not(ATOM x) then f(x) = H(x, f(CAR x), f(CDR x))) and (if not(ATOM x) then g(x) = H(x, g(CAR x), g(CDR x))) ) then f=g.
The recursion result allows us to conclude that a particular form of recursion gives a unique function or perhaps is undefined.
The above are more for interest than to be memorized.
The data in LISP is a list. Internally all lists are either empty, atomic or
a CONS-pair (Constructed Pair)
cons [ car | cdr ]
A CONS-pair-pair is constructed like this: (CONS 'A 'B) and is printed (A . B). It is also called a "Dotted pair"
Lists of more than 2 items are encoded using CONS-pairs as follows:
Here is a page of pointers to many WWW pages on LISP:
[ lisp.html ]
The Source code for LISP is online. You may download and make copies of this
code, compile it on your machine and use it any non-profit way you like. Do
not sell it - improve it and give it away.
[ http://cse.csusb.edu/dick/cs320/lisp/src/ ]
. . . . . . . . . ( end of section Details) <<Contents | End>>
. . . . . . . . . ( end of section Introduction to LISP) <<Contents | End>>