Function template for several-case input

If the data definition for the input reveals several possible cases, e.g.

Data definition:
A bank-balance is a number, falling into one of the categories:
  1. under $500.00
  2. at least $500.00 but under $1000.00
  3. at least $1000.00 but under $5000.00
  4. at least $5000.00
then the function body will (almost always) be a cond with the same number of clauses:
  (define (interest-rate balance)
     (cond [(< balance 500.00) ...]
	   [(and (>= balance 500.00)
		 (< balance 1000.00)) ...]
	   [(and (>= balance 1000.00)
		 (< balance 5000.00)) ...]
	   [(>= balance 5000.00) ...]))
  
Note that by taking advantage of the order of the tests, you can frequently simplify them:
  (define (interest-rate balance)
     (cond [(< balance 500.00) ...]
	   [(< balance 1000.00) ...]
	   [(< balance 5000.00) ...]
	   [else ...]))
  

Last modified: Thu Nov 4 16:47:27 EST 1999
Stephen Bloch / sbloch@adelphi.edu