next up previous




MASSACHVSETTS INSTITVTE OF TECHNOLOGY
Department of Electrical Engineering and Computer Science
6.001--Structure and Interpretation of Computer Programs
Fall Semester, 1998


Lecture Notes, September 9

Scheme Basics

Language Components

Rules for Scheme

1.
(Almost) Every expression has a value (which is returned when the expression is evaluated).
2.
Every value has a type.

Rules for Evaluation

1.
If expression is self-evaluating, return value.
2.
If a name, return value associated with that name in the environment.
3.
If a special form, do something special.
4.
If a combination, then
(a)
Evaluate all of the subexpressions of the combination (in any order).
(b)
Apply the operator to the values of the operands (the arguments) and return the result.

Rules for Application

1.
If procedure is primitive (built-in), just do it.
2.
If procedure is a compound procedure, then evaluate the body of the procedure with each formal parameter replaced by the corresponding actual argument value.

Taxonomy of Expressions

Approximations for Square Root

(define try
  (lambda (guess x)
    (if (good-enuf? guess x)
        guess
        (try (improve guess x) x))))

(define improve
  (lambda (guess x)
    (average guess (/ x guess))))

(define average
  (lambda (a b)
    (/ (+ a b) 2)))

(define good-enuf?
  (lambda (guess x)
    (< (abs (- (square guess) x)) 0.001)))

(define sqrt
  (lambda (x) (try 1 x)))

About this document ...

This document was generated using the LaTeX2HTML translator Version 98.1p1 release (March 2nd, 1998)

Copyright © 1993, 1994, 1995, 1996, 1997, Nikos Drakos, Computer Based Learning Unit, University of Leeds.

The command line arguments were:
latex2html lec1.

The translation was initiated by Duane Boning on 1998-09-10


next up previous
Duane Boning
1998-09-10