]> gitweb.factorcode.org Git - factor.git/blob - extra/taxes/usa/usa.factor
factor: trim using lists
[factor.git] / extra / taxes / usa / usa.factor
1 ! Copyright (C) 2008 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors kernel math math.order sequences ;
4 IN: taxes.usa
5
6 ! Withhold: FICA, Medicare, Federal (FICA is social security)
7
8 TUPLE: tax-table entity single married ;
9 C: <tax-table> tax-table
10
11 GENERIC: adjust-allowances* ( salary w4 tax-table entity -- newsalary )
12 GENERIC: withholding* ( salary w4 tax-table entity -- x )
13
14 : adjust-allowances ( salary w4 tax-table -- newsalary )
15     dup entity>> adjust-allowances* ;
16
17 : withholding ( salary w4 tax-table -- x )
18     dup entity>> withholding* ;
19
20 : tax-bracket-range ( pair -- n ) first2 swap - ;
21
22 : tax-bracket ( tax salary triples -- tax salary )
23     [ [ tax-bracket-range min ] keep third * + ] 2keep
24     tax-bracket-range [-] ;
25
26 : tax ( salary triples -- x )
27     0 -rot [ tax-bracket ] each drop ;
28
29 : marriage-table ( w4 tax-table -- triples )
30     swap married?>>
31     [ married>> ] [ single>> ] if ;