Notes on the History of LISP: LISP was invented in the late 1950's and early 1960's at M.I.T. by John McCarthy. LISP is based in part on the Lambda Calculus, a mathematical formalism developed by Alonzo Church (1903-1995).
LISP is the second-oldest language still in widespread use (the oldest is Fortran). Two dialects of LISP are widely used today: Scheme and Common LISP. Scheme is a small, uniform dialect that is good for teaching because of its simplicity. Common LISP is a large, ``industrial-strength'' dialect that is standardized and is available in several commercial versions. In this course, we will use an implementation of LISP called Allegro Common LISP .
Most programming languages require learning the syntax of many different kinds of statements. In contrast, LISP syntax is simple and uniform. Much of the work in learning LISP is learning the names and effects of the system functions that form the core of the language.
Preparation: Read sections 2.1-2.4 of the textbook.
To run the LISP system, type acl <Enter> into a
dtterm window. Allegro Common LISP will print out a
header and then issue its own prompt [USER(1):], indicating
that it is ready to examine and process any LISP program that you submit to
it:
Allegro CL 4.3 [HP Prism; R1] (4/5/96 19:17) Copyright (C) 1985-1996, Franz Inc., Berkeley, CA, USA. All Rights Reserved. ;; Optimization settings: safety 1, space 1, speed 1, debug 2. ;; For a complete description of all compiler switches given the ;; current optimization settings evaluate (EXPLAIN-COMPILER-SETTINGS). USER(1):
To shut down LISP, press <Ctrl/d> at the LISP prompt, and confirm you
really wish to stop. Allegro Common LISP quits after printing an
exit message. Alternatively, you could type (exit) at the
LISP prompt.
Numbers are expressions, whose value or meaning is the number
itself.
Type several numbers into Allegro Common LISP, typing
one number at a time. For example, at the LISP prompt, type
7
-10
3.1415926535
In each case, note how Allegro Common LISP responds.
3/5
-18/19
10/34
How many digits are printed in the answer for rational numbers?
(- 27 3)
(/ 17 2)
(/ 17 -2)
(/ 17 2.0)
(truncate (/ 17 4))
(round (/ 17 4))
(mod 17 3)
(sqrt 4)
(sin 0.5)
(sqrt -2)
(gcd 12 15)
(gcd 9 10)
(+ (* 3 2) (/ 8 4))
| hi | TwoBeOrNot2Be | This-is-a-symbol. |
(setf root2 1.4142135)
Now enter root2 into LISP and determine what happens.
(setf pi 3)
Explain what happens.
(setf a 4)
(setf b 5)
(setf c 1)
(setf discriminant
(- (* b b) (* 4 (* a c))))
(setf root1
(/ (+ (- b) (sqrt discriminant))
(* 2 a)))
(setf root2
(/ (- (- b) (sqrt discriminant))
(* 2 a)))
Determine the values for a, b, c, discriminant, root1, and
root2 . Now, redefine the values of a, b and c . Do the values of root1 and root2 change?
(setf discriminant
(- (* b b) (* 4 a c)))
Check the values LISP returns for each of the following expressions:
(* 2) (* 2 2) (* 2 2 2) (* 2 2 2 2) (* 2 2 2 2 2)What happens if you do not supply any operands?
(*)Hypothesize why you get this result.
= all the same /= all different < monotonically increasing > monotonically decreasing <= monotonically nondecreasing >= monotonically nonincreasingThe result of a comparison will be true (
T) or false
(NIL). Try these operations on several sets of numbers including the following:
(= 1 1.0) (= 1 2/2 (+ (/ 1 2) 0.5)) (< 2 4 5 8 10 12) (< 2 4 8/2 5 10 12) (<= 2 4 8/2 5 10 12)Be sure you can explain each of these results. What happens if you try the following:
(= 1) (=)
(quote pi)
(quote pi) may be abbreviated 'pi . Try typing this at
the keyboard as well.
(lambda (x) (* x x))
This expression indicates that the input parameter is x and the
result of the function will be computed as (* x x).
Apply this function to the values 1, 3, -2 by typing:
((lambda (x) (* x x)) 1)
((lambda (x) (* x x)) 3)
((lambda (x) (* x x))-2)
What happens if you try to apply the function to all three values at once?
((lambda (x) (* x x)) 1 3 -2)
In LISP, a lambda expression is called a procedure.
lambda. If we call the above function f, then the
above computations could be done as follows:
(defun f (x)
(* x x))
(f 1)
(f 3)
(f -2)
This document is available on the World Wide Web as
http://www.math.grin.edu/~walker/courses/261/lab-beginning-LISP.html