MASSACHVSETTS INSTITVTE OF TECHNOLOGY

Department of Electrical Engineering and Computer Science
6.001 -- Structure and Interpretation of Computer Programs

March 13, 1997

Lecture Notes

Announcements

Quiz 1
Wednesday, March 19, Walker Gym (3rd floor) You bring one sheet of personal notes, we'll bring Scheme manuals and text books.

Java
Please start familiarizing yourself with the Java development environment of your choice. J++ will arrive shortly.

The Mantras (Updated)

  1. Every expression1 has a value.
  2. To find the value of a combination,
  3. The value of a lambda expression is a compound procedure.3
  4. The value of a quote expression is the thing quoted.
Notes:
  1. Except for errors, infinite loops, and the define special form.
  2. To apply a compound procedure to arguments use the arguments and all three parts of the procedure (create, fill, link, evaluate).
  3. A compound procedure ("double bubble") has parameters, body, and an environment. The parameters and the body, together, are called the text.

The Example

   (define make-adder
     (lambda (x)
       (lambda (y)
	 (+ x y))))

   (define add-2 (make-adder 2))
   (define add-3 (make-adder 3))

   (add-2 5)  ; ==> 
   (add-3 5)  ; ==> 
   (add-2 12) ; ==> 

Substitution model
















Definitions

A quantifier controls names within a specified scope. The names it controls are called the bound variables of the quantifier, and we say "the variables are bound to values" by the quantifier within its scope.

lambda is a quantifier. Its parameters are the bound variables, and its scope is the body of the lambda expression.

Those variables that are not controlled by a quantifier are called free. Bound variables can be renamed by uniformly changing them throughout the scope of the controlling quantifier, provided they aren't renamed to a name that is used freely in that scope.

Scope lines

	  (define make-adder

	    (lambda (x)

	      (lambda (y)

		(+ x y)
              )
            )
          )

Environment model


















Rules of the Environment Model

Rule 1: To find the value of an expression you must have both an expression and an environment.

Rule 2: Procedures have two parts: text (composed of the procedure's parameters and its body) and an environment.

Rule 3: When you apply a procedure to arguments, be sure to use the arguments and all three parts of the procedure.

Details of the Environment Model

  1. Variable: look it up in the environment.
  2. lambda expression: create a compound procedure ("double bubble"). The text (i.e. parameters and body) come from the lambda expression; the environment is the one you are using to evaluate the lambda expression.
  3. Combination: "Evaluate, then apply". To apply a compound procedure ("double bubble"):