Created
August 3, 2012 13:40
-
-
Save pclouds/3247794 to your computer and use it in GitHub Desktop.
PIT calculation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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