- Modularity, Objects and State
Modularity, Objects and State
“modular”: naturally breaks into coherent parts that can be separately developed and maintained.
design strategy: modeling physical objects with computational objects.
organizational strategies: objects view and streams view
Assignment and Local State
Objects can hold states that are determined by its history.
The Benefits of Introducing Assignment
- Objects like pseudo random generators have to hold states within them.
The Costs of Introducing Assignment
- Substitution model no longer applies, because we have to somehow distinguish “name before
set!” and “name after
- Same call can return different values.
- Referentially transparency is violated by
One have to care about order of execution.
samenessitself is ambiguous:
- Sameness at the same time is clear: A and B are different if changing A does not affect B.
- Change over time is harder to define: are A(time1) and A(time2) both As?
- This complication is a consequence of our perception of “object”, and not of a programming language.
The Environment Model of Evaluation
- A variable is no longer a “name” of value.
It is merely a name of “place” where value can be stored.
- Environments are structures that maintain such places.
- sequence of frames
- frame: a table of bindings
- binding: name-value mapping
- Evaluating an expression requires some frame as context
(+ 1 1)requires the definition of
+as a procedure of sum
The Rules for Evaluation
- Specification of Evaluation Process
- Evaluate every subexpressions
- Apply the operator subexpression to values of operand subexpressions
- Procedure: definition
- only way to create: by evaluating
(lambda (bar) ...)
(define (foo bar) ...)form is but syntactic sugar
codeare from the
pointer-to-envpoints to the enviorment where
- Procedure: application