Lecture: Modeling State with Assignment and Streams

Background Material



Assignment allows a program to update a variable and hence model the state of an object through changes in the variable. As we will see, in lambda calculus lecture technically not having assignment does not limit what can be computed; however, using assignment as indicated above does make it easier to write programs that model state. The disadvantage of allowing assignment is that the semantics of the resulting programs are much harder to understand and describe.

In this lecture we will illustrate how to use assignment in scheme and to use assignment along with local variables to produce functions that model the state of an object. We will also investigate that the simple semantics that work for pure functional languages does not work when assignment is allowed and will review the environment model that does allow assignment.

After discussing the benefits and costs of assignment, we will introduce another computational model, streams, that can be used to model state but does not require assignment. Streams, sequences of data - potentially infinite, and stream processing provides a useful abstraction for many computational problems. We will illustrate stream processing, discuss a clever technique for implementing streams that make them much more efficient, and see how they can be used to model state.


  1. Modeling state with assignment in scheme (SICP sec. 3.1.1)
  2. Substitution model for function evaluation (SICP sec. 1.1.5, Louden sec. 11.8)
  3. Cost of assignment (SICP sec. 3.1.3)
  4. Environment model for function evaluation (SICP sec. 3.2, Louden sec. 13.2)
  5. Stream processing (SICP sec. 3.5, Louden sec. 11.5)

Sample Functions



Created: Apr. 10, 2007 (revised April 5, 2012) by jjohnson AT cs DOT drexel DOT DOT edu