/extra/taxes/usa/usa.factor

http://github.com/abeaumont/factor · Factor · 33 lines · 21 code · 9 blank · 3 comment · 1 complexity · 9431afe689caf9e1947c443db945b717 MD5 · raw file

  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 ;
  6. IN: taxes.usa
  7. ! Withhold: FICA, Medicare, Federal (FICA is social security)
  8. TUPLE: tax-table entity single married ;
  9. C: <tax-table> tax-table
  10. GENERIC: adjust-allowances* ( salary w4 tax-table entity -- newsalary )
  11. GENERIC: withholding* ( salary w4 tax-table entity -- x )
  12. : adjust-allowances ( salary w4 tax-table -- newsalary )
  13. dup entity>> adjust-allowances* ;
  14. : withholding ( salary w4 tax-table -- x )
  15. dup entity>> withholding* ;
  16. : tax-bracket-range ( pair -- n ) first2 swap - ;
  17. : tax-bracket ( tax salary triples -- tax salary )
  18. [ [ tax-bracket-range min ] keep third * + ] 2keep
  19. tax-bracket-range [-] ;
  20. : tax ( salary triples -- x )
  21. 0 -rot [ tax-bracket ] each drop ;
  22. : marriage-table ( w4 tax-table -- triples )
  23. swap married?>>
  24. [ married>> ] [ single>> ] if ;