[previous] [up] [next]     [index]
Next: The Need for Memory Up: Changing the State of Previous: A First Useful Example

Designing Functions with Memory

Section [cross-reference] motivated the idea of functions with memory; section [cross-reference] explained how variable definitions and set! together can achieve the effect of memory. It is now time to discuss the design of programs with memory.

Designing functions with memory requires three important steps:

  1. We must determine that a program requires memory.
  2. We must identify the data that goes into the memory.
  3. We must understand which of the services are supposed to modify the memory and which are to use the memory.
The need for the first step is obvious. Once we know that a program requires memory, we must conduct a data analysis for the program's memory. That is, we must figure out what kind of data the program puts into memory and retrieves from there. Finally, we must carefully design those functions for the program that change the memory. The others are those that use the variables (without modification); they are typically designed with one of the recipes we have already discussed.





PLT