In Linux
Download the free version
of ACL5.0 at www.franz.com
Under Unix
Run ACL, possibly within
Gnu Emacs.
On the Mac
Use XLISP-STAT or Macintosh
Common Lisp
At the "top level" of
interpretation, a Lisp "listener"
waits for the user
to type in an S-expression on one
or more lines.
Parentheses must balance.
Double quotes (for strings) must balance.
Next, the interpreter tries to evaluate the expression.
Finally, the value is printed out.
Then the cycle repeats
If the expression is a symbol, then
its SYMBOL-VALUE,
if any, is returned. If it has not value, then the interpreter
reports that it is an Unbound variable.
If the expression is a list, then
the interpreter tries to use
the first
element of the list as an operator -- either a
function,
a special form, or a macro.
If the first element is the name of a function,
then the remaining elements of the list are evaluated,
and the function is applied to the resulting values.
If the first element is the name of a special form,
then the arguments are processed in some
specific way, and some value is returned.
If the first element is the name of a macro, then
the macro expander function for that macro is
applied to a list of the remaining elements,
and the expression that results is evaluated.
Many arithmetic functions
can take an arbitrary
number
of arguments.
> (+ 1
2 3)
6
> (+ 1)
1
> (+)
0
> (- 10 1)
9
> (- 10 1
2)
7
> (/ 10
2)
5
> (/ 10
2 3)
5/3
A ratio is not only a mathematical
concept but a
Common Lisp-supported type of number.
> (+ 5/3 1/3)
2
> (+ 5/3 1/4)
23/12
Floating point numbers are
an absorbing type.
> (+ 1/2 0.25)
0.75
> 1/2.
Error unbound variable '1/2.'
A Bignum is an integer stored
in a format that
allows arbitrarily large magnitudes.
> (defun fact (n)
(if (= n 0) 1
(* n (fact (1- n))) )) )
FACT
> (fact 5)
120
> (fact 20)
2432902008176640000
> (+ * 0.0)
2.432902e+18
Lisp lists are typically represented
internally as linked lists.
FIRST accesses the element "here"
at the head of the list.
REST accesses what it pointed to
by outgoing pointer from
the first cell.
> (cons 'a '(b c))
(A B C)
> (cons 'a '() )
(A)
> (cons 'a 'b)
(A . B)
A dotted pair represents a single
"cons" or memory cell
that contains a FIRST and REST
component.
> ( )
NIL
> nil
NIL
> (= 1 2)
NIL
> (rest '(a) )
NIL
> (null '() )
T
> (null '(a) )
NIL
Lists can be nested to any level
> '(a b (c d
(e f) g) )
(A B (C D (E F) G))
Here's a function definition with
a simple conditional:
> (defun big-or-small
(n) (if (> n 99) 'big 'small) )
BIG-OR-SMALL
> (big-or-small 100)
BIG
> (big-or-small 99)
SMALL
Then we can bring it into a Lisp
session...
> (load "FACT.LSP")
2. Write a function TO-ORDINAL that
takes as its argument
an integer in the range 1 to 3
and outputs FIRST, SECOND,
or THIRD. For example it
should behave this way:
> (to-ordinal 2)
SECOND
3. Write a recursive function that
sums the first n odd numbers.
It should have the behavior...
> (sum-odd-numbers 5)
9
Last modified: October 2, 1998
Steve Tanimoto