]> gitweb.factorcode.org Git - factor.git/blob - extra/taxes/usa/usa.factor
Merge branch 'master' into new_ui
[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 arrays assocs kernel math math.intervals
4 namespaces sequences money math.order taxes.usa.w4
5 taxes.usa.futa math.finance taxes.usa.fica
6 taxes.usa.federal ;
7 IN: taxes.usa
8
9 ! Withhold: FICA, Medicare, Federal (FICA is social security)
10
11 TUPLE: tax-table entity single married ;
12 C: <tax-table> tax-table
13
14 GENERIC: adjust-allowances* ( salary w4 tax-table entity -- newsalary )
15 GENERIC: withholding* ( salary w4 tax-table entity -- x )
16
17 : adjust-allowances ( salary w4 tax-table -- newsalary )
18     dup entity>> adjust-allowances* ;
19
20 : withholding ( salary w4 tax-table -- x )
21     dup entity>> withholding* ;
22
23 : tax-bracket-range ( pair -- n ) first2 swap - ;
24
25 : tax-bracket ( tax salary triples -- tax salary )
26     [ [ tax-bracket-range min ] keep third * + ] 2keep
27     tax-bracket-range [-] ;
28
29 : tax ( salary triples -- x )
30     0 -rot [ tax-bracket ] each drop ;
31
32 : marriage-table ( w4 tax-table -- triples )
33     swap married?>>
34     [ married>> ] [ single>> ] if ;