- Allows representation of complex interrelationships among data (e.g., in AI).
- Uses linked representation of list (i.e., pointers).
- Only two data objects:
- atom ::= <identifier> | <literal number>
E.g.,
- list ::= ( {<atom> | <list>}* )
I.e., ordered collection of atoms and/or lists;e.g.,
(Sam)
(Sam Bill)
(Sue (Sam Bill) (Sam))
((Sue (Sam Bill)) (Sam))
()
- Recursive -- Lists, being recursive structures, lend themselves to recursive processing.
- Recursion is implemented with a stack (i.e., a push-down list).
- Interpreted -- Most LISP systems provide interactive interpreters.
- John McCarthy
wrote the first LISP interpreter (in LISP) when he wrote a universal LISP
function which could interpret any other LISP function in order to investigate universal functions
as a basis for the theory of computing (cf. the universal Turing machine).
See John McCarthy's
History of Lisp.
E.g., if the primary prompt is >
and the error condition prompt is
>>
> (+ 2 3)
Common LISP
5
> 3
3
A literal number evaluates to itself.
> hello
Error: The variable HELLO is unbound.
'hello' is undefined.
>> :q
> (bye)
Or Ctrl-D [UNIX]
Symbolic language -- Since LISP processes lists, the LISP universal function required LISP programs
to be represented as lists.
- A program and data have the same representation.
- It is easy to write LISP programs to manipulate LISP programs.
- Notation:
- M-expression (meta-language)
E.g.,
f [x+y; u*z]
- S-expression (symbolic language) ::= <atom> | <list>
E.g.,
(f (plus x y) (times u z))
or, in Common LISP,
(f (+ x y) (* u z))
=> LISP = Lots of Idiotic Single Parentheses
Evaluation of S-expressions
- atoms
- If the atom is bound to a value, then the atom evaluates to that value.
- Atoms which are literal numbers are pre-bound to their own value.
- If an atom is not bound to a value, an error occurs if an attempt is made to evaluate it.
- lists
Primitive functions -- Each LISP environment has some atoms which are pre-bound to functions.
E.g.,
> (* 3 4)
12
> (mult 3 4)
Error: The variable MULT is unbound.
>> :q
> (atom 5)
T
'atom' is a predicate; 'T' means 'true'.
> 3
3
>
Pure functions -- A pure function is a functions which has no effect other than the computation of a value.