1 ! Copyright (C) 2008 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors kernel math math.order sequences ;
6 ! Withhold: FICA, Medicare, Federal (FICA is social security)
8 TUPLE: tax-table entity single married ;
9 C: <tax-table> tax-table
11 GENERIC: adjust-allowances* ( salary w4 tax-table entity -- newsalary )
12 GENERIC: withholding* ( salary w4 tax-table entity -- x )
14 : adjust-allowances ( salary w4 tax-table -- newsalary )
15 dup entity>> adjust-allowances* ;
17 : withholding ( salary w4 tax-table -- x )
18 dup entity>> withholding* ;
20 : tax-bracket-range ( pair -- n ) first2 swap - ;
22 : tax-bracket ( tax salary triples -- tax salary )
23 [ [ tax-bracket-range min ] keep third * + ] 2keep
24 tax-bracket-range [-] ;
26 : tax ( salary triples -- x )
27 0 -rot [ tax-bracket ] each drop ;
29 : marriage-table ( w4 tax-table -- triples )
31 [ married>> ] [ single>> ] if ;