If the data definition for the input reveals several possible cases, e.g.
Data definition:then the function body will (almost always) be a cond with the same number of clauses:
A bank-balance is a number, falling into one of the categories:
- under $500.00
- at least $500.00 but under $1000.00
- at least $1000.00 but under $5000.00
- at least $5000.00
(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 ...]))