2500 F '12
The Hand In
Set 1
Set 2
Set 3
Set 3h
Set 4
Set 4h
Set 5
Set 5h
Set 6
Set 6h
Set 7
Set 7h
Set 8
Set 9
Set 8h
Set 10
Set 9h
Set 11
Set 12
Set 10h

The Recipes

Design Recipe for Abstraction

  1. Are the function definitions similar? The answer is certainly yes, if they are based on the same template. If not, reconsider abstracting over them. -- Mark the differences in pairs and connect the pairs via lines; we call those difference lines.
  2. Create a function definition that looks just like one of the two. Give it a new distinct name. Add one parameter to the function header per "difference lines". Also add those parameters to the recursive calls. Use the parameters where the different expressions used to be.
  3. Can you re-define the original functions using the abstraction you created? Do so.
  4. Do the re-definitions pass the test suites for the original functions? If not, you're in trouble.
  5. Develop a general contract for the abstraction.
  6. State the purpose statement in terms of "..." terms. See page 313 in How to Design Programs.

Design Recipe for Structural Data

  1. What kinds of data are involved? Create data definitions. If they look complex, construct examples according to the data definitions, just to make sure they work.
  2. What kinds of data does the function consume? Which kind does it produce? And what is its purpose? (in one line)
  3. Can you make up examples of inputs? What should the function produce for these inputs?
  4. Let's construct the template:
    1. Does the data definition (of the main argument) mention clauses? If so, use a cond with as many cases as there are clauses in the data definition.
    2. How can you distinguish these kinds of data with conditions involving the main parameter?
    3. Are structs involved? If so, write down all the selector expressions. (Do so on a per-clause basis.)
    4. Does the data definition involve any self-references (or cross-references)? If so, use recursion in the template to express these "arrows".
  5. Let's code:
    1. Can you deal with the simple cond cases? Your examples should give you some hints.
    2. What do the expressions in the recursive cases compute? Use the purpose statement of the function to figure out what the recursive function application computes.
    3. How can you combine the results of these expressions so that the function returns the desired value?
  6. Did you turn the examples into tests? You may want to do this as you develop functional examples.

last updated on Sun Dec 2 14:52:34 EST 2012generated with Racket