Skip to content

Instantly share code, notes, and snippets.

@pclouds
Created August 3, 2012 13:40
Show Gist options
  • Save pclouds/3247794 to your computer and use it in GitHub Desktop.
Save pclouds/3247794 to your computer and use it in GitHub Desktop.
PIT calculation
#!/usr/bin/scheme-r5rs
;; Calculate Vietnam Personal Income Tax
;; Input in million VND
(let* ((thresholds '((09 . 0.00)
(02 . 0.05)
(03 . 0.10)
(05 . 0.15)
(10 . 0.20)
(20 . 0.25)
(40 . 0.30)
( 0 . 0.35)))
(args (cond-expand
(gauche *argv*)
(gambit-c (cdr (command-line)))
(chibi (cdr (command-line)))))
(total (string->number (car args)))
(tax
(let loop ((value total)
(thresholds thresholds))
(let* ((limit (caar thresholds))
(rate (cdar thresholds))
(next (cdr thresholds))
(amount (if (and (pair? next)
(>= value limit))
limit
value)))
; (println amount " * " rate " = " (* amount rate))
(+ (* amount rate)
(if (pair? next)
(loop (- value amount) next)
0))))))
(display tax)
(newline))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment