next up previous
Next: About this document

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

Recitation -- Wednesday, April 21

1. Memoization and Streams

Memoization is a technique to improve performance by recording previously computed values. Whenever a computation is repeated, the recorded result is used instead of performing the same work a second time. Today, we will look at a simple example of how to memoize a procedure:

Consider now what happens if we change the definition of delay as follows.
(delay s) <==> (memoize (lambda () s))
Draw the environment diagrams for the following expressions with and without stream memoization.

2. Playing with Scope

Let's take a look at our old friend make-acct:

Why does b have a balance of 100 and not 1000? Quickly sketch the environment diagram for the above expressions to see why.

3. Re-scoping a procedure

Consider a new special form called rescope that takes a procedure and returns a procedure with the same parameters and body, but whose environment pointer points to the current environment. Consider defining another account c by rescoping a (instead of by calling make-acct).

Let's add the special form rescope to the mc-evalutator.

(1) Define Data Abstraction

(2) Add the appropriate cond clause to mc-eval

(3) Write eval-rescope

4. Grabbing procedure's scope

Consider a new special form called inscope that takes a procedure and an expression and then evaluates the expression with respect to the procedure's environment. For example

Let's add the special form inscope to the mc-evalutator.

(1) Define Data Abstraction

(2) Add the appropriate cond clause to mc-eval

(3) Write eval-inscope





next up previous
Next: About this document



Michael E. Leventon
Wed Apr 21 10:48:42 EDT 1999