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)
- 5pm to 7pm (you may not leave early)
- 7pm to 9pm
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)
- Every expression1 has a value.
- To find the value of a combination,
- Find the values of the subexpressions, in any order.
- Apply2 the value of the first to the values of the
rest.
- The value of a lambda expression is a compound procedure.3
- The value of a quote expression is the thing quoted.
Notes:
- Except for errors, infinite loops, and the define special
form.
- To apply a compound procedure to arguments use the arguments and
all three parts of the procedure (create, fill, link, evaluate).
- 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
- Variable: look it up in the environment.
- 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.
- Combination: "Evaluate, then apply". To
apply a compound procedure ("double bubble"):
- Create a new frame [parameters].
- Fill the frame [arguments].
- Link the frame to make it an environment [environment].
- Evaluate the body using the new environment [body].