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.3855. These examples illustrate
some important recursive techniques:
- 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).
- Before recurring, check the trivial (or base case).
- Always recur on a smaller problem: use (cdr arg)
if arg is a list, ( arg
1) if arg is a natural number, etc.
- Program correctness can be shown using mathematical induction.
- 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