Advertisement
Guest User

Untitled

a guest
Dec 9th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Racket 0.67 KB | None | 0 0
  1. (: calc-tax-bracketed-rate (-> Nonnegative-Real BracketSpec Nonnegative-Real))
  2. (define (calc-tax-bracketed-rate income brackets)
  3.   (let calc-impl ([income income]
  4.                   [brackets brackets]
  5.                   [tax 0.0])
  6.     (match-let ([(cons lo rate) (car  brackets)]
  7.                 [(cons hi    _) (cadr brackets)])
  8.       (if (or (< income lo) (null? brackets))
  9.           ;; stopping conditions:
  10.           ;;  - income < lo   =>  we're one bracket too high
  11.           ;;  - null? bracket =>  we ran out of brackets
  12.           tax
  13.           (calc-impl income
  14.                      (cdr brackets)
  15.                      (+ tax (* rate (- (min (+ hi 1) income) lo))))))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement