Notes on the History of Scheme: 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 Scheme called Chez Scheme .
Most programming languages require learning the syntax of many different kinds of statements. In contrast, Scheme (and Lisp) syntax is simple and uniform. Much of the work in learning Scheme is learning the names and effects of the system functions that form the core of the language. This course presents the system functions and covers other functions that are present in Common Lisp.
Lisp is especially used for work in Artificial Intelligence. For example, CS 261, Artificial Intelligence, uses programming in LISP in its study of expert systems.
Steps for this Lab:
scheme in the dtterm
window.
(- 27 3)
(/ 17 2)
(/ 17 -2)
(/ 17 2.0)
(truncate (/ 17 4))
(modulo 17 3)
(sqrt 4)
(sin 0.5)
(sqrt -2)
(+ (* 3 2) (/ 8 4))
| hi | TwoBeOrNot2Be | This-is-a-symbol. |
(define pi 3.141592)
Now enter pi into Scheme and determine what happens.
(define pi 3)
Now what happens if you type the symbol pi?
(define a 4)
(define b 5)
(define c 1)
(define discriminant
(- (* b b) (* 4 (* a c))))
(define root1
(/ (+ (- b) (sqrt discriminant))
(* 2 a)))
(define 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?
To select material from Netscape, move the cursor to the beginning of a section and push down the left mouse button. Then, holding the button down, move the mouse to the end of the section. (The entire section now should be highlighted.) When the desired section is highlighted, stop pressing on the left mouse button -- the section should stay highlighted. Now move the mouse to where you want to paste the material, and click the middle mouse button.
For practice, select and paste the above sequence of define statements into Scheme within the dtterm window.
(define discriminant
(- (* b b) (* 4 a c)))
Check the values Scheme 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.
(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 Scheme, a lambda expression is called a procedure.
(define f
(lambda (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/153/lab-symbols.html