Advertisement
Guest User

Untitled

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