LISP is discussed in some detail in the book "
Metamagical Themas" by
Douglas Hofstadter. He describes how since in LISP it is easy to
write
recursive functions, and programs and data are both
represented in the same way, as lists, LISP could be a good language
to use for
Artificial Intelligence. He gives several example LISP
programs, including one to solve the
Tower of Hanoi puzzle and one
to expand
recursive acronyms to a given depth.
Here's some simple example LISP code. These examples use Emacs LISP.
To try them out, start emacs and type "Meta-X
lisp-interaction-mode". After typing each LISP expression, press
Ctrl-J to have it evaluated.
The hello world program is completely trivial; just type
'(hello world) Ctrl-J
and you'll get back the output "(hello world)". The single quotation
mark at the beginning means "Don't try to do anything with this
list, like treating hello as a function, just treat it as a single
unit".
Now here's how to count from 1 to 10 in LISP. You could just type '(1
2 3 4 5 6 7 8 9 10), of course, but the method below is more
flexible as it allows the program to count arbitrarily high. Type
the following into your emacs session, then type Ctrl-J. You can
leave out the lines beginning with semicolons, as these are comments
which I've included to explain what the program is doing.
;; Define the recursive function "count".
;; (count x y) generates a list of integers from x to y inclusive.
(defun count (x y)
;; If x and y are the same, the output is (x).
(cond ((= x y) (list x))
;; If x < y, the output is x followed by
;; the list of integers from x+1 to y.
((< x y) (cons x (count (+ 1 x) y)))
;; Otherwise (x>y), this function has been called with invalid
;; arguments.
(t "ERROR"))
)
Now if you type (count 1 10) then Ctrl-J, you'll get back the correct
list of numbers.