RU beehive logo ITEC dept promo banner
ITEC 380
2008fall
ibarland

homeinfolecturesexamsarchive

lect03a
templates; recursive data

The steps of design recipe (taken from How to Design Programs).
1. Data Def'n
2. Examples of Data
3. Template for functions handling the data
4a Write function header
 b Write function comments
 c Write test cases
 d Write function body
   i.   a cond line for each variant of union data
   ii.  pull out fields for each line handling a struct
   iii. add natural-recursion call, if present.
5. run tests

- For aggregate data (structs):
  The recipe pulls out each field, to remind you 
  what pieces you have to work with.
- For union data:
  One 'cond' line for each type of data.
  If that line is itself a struct, pull out each fields.
  If one of those fields is a recursive type, add the natural recursive call.

examples of template and code for:
  animal-length
  too-long

data def'n:
 of list-of-data: empty, or cons.
Make examples of the data.
Note that this is a recursive definition.
Our code to handle a list will be recursive 
  (no coincidence: good code mirrors its data.)


To do for next time: write:
; num-too-long : (-> (list-of animal) natnum)
; Count how many animals in the list are too long.

homeinfolecturesexamsarchive


©2008, Ian Barland, Radford University
Last modified 2008.Sep.15 (Mon)
Please mail any suggestions
(incl. typos, broken links)
to iba�rlandrad�ford.edu
Powered by PLT Scheme