Week of 2 February 1998

We begin the week with some examples of recursive functions: nth-elt, list-length, remove-first, remove, and subst, which are all defined in EOPL, pp.38­55. These examples illustrate some important recursive techniques:

  1. The structure of a program reflects the structure of its data: recursion is used if the data's type definition is specified inductively (last week's topic).
  2. Before recurring, check the trivial (or base case).
  3. Always recur on a smaller problem: use (cdr arg) if arg is a list, arg 1) if arg is a natural number, etc.
  4. Program correctness can be shown using mathematical induction.
  5. Eliminate redundant computations using auxiliary functions (or local variables with let).

Additional examples of recursive functions shall be presented on Wednesday. On Friday, we shall discuss Section 2.3, Static Properties of Variables.


CS 103 Home Page
Robert Snapp's Home Page