#!/usr/local/bin/kermit

; i n c o m e _ t a x  --  Sample income bracketed tax calculation
;
; Author:  Dat Thuc Nguyen, 24 Sep 2001
;
; Adapted from:
; http://www.scheme.com/tspl2d/
;
; \%1 Income
;
define income_tax {
    if < \v(argc) 2 exit 1 Usage: income_tax income
    if not float \%1 exit 1 \%1: not a number
    if < \%1 0 .\%1 = 0
    (if (<= \%1 10000) (* \%1 .05)
        (if (<= \%1 20000) (+ (* (- \%1 10000) .08) 500.00)
            (if (<= \%1 30000) (+ (* (- \%1 20000) .13) 1300.00)
                (+ (* (- \%1 30000) .21)  2600.00)
            )
        )
    )
}

echo \fsexpr(income_tax 5000)   ; => 250.0
echo \fsexpr(income_tax 15000)  ; => 900.0
echo \fsexpr(income_tax 25000)  ; => 1950.0
echo \fsexpr(income_tax 50000)  ; => 6800.0

exit
