]> gitweb.factorcode.org Git - factor.git/commitdiff
money: cleanup.
authorJohn Benediktsson <mrjbq7@gmail.com>
Tue, 19 Apr 2016 03:16:33 +0000 (20:16 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Tue, 19 Apr 2016 03:16:33 +0000 (20:16 -0700)
extra/money/money.factor

index a3ac4ebb136715a01cdfedc0f4650b16462fe1eb..9db6b19d6b30a4d3fdc6b644f8b80302419c34ce 100644 (file)
@@ -1,33 +1,42 @@
-USING: io kernel math math.functions math.parser parser lexer
-namespaces make sequences splitting grouping combinators
-continuations ;
+! Copyright (C) 2008 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: grouping io kernel lexer math math.functions math.parser
+namespaces sequences splitting ;
 IN: money
 
 SYMBOL: currency-token
-CHAR: $ \ currency-token set-global
+CHAR: $ currency-token set-global
+
+<PRIVATE
 
 : dollars/cents ( dollars -- dollars cents )
     100 * 100 /mod round ;
 
-: (money>string) ( dollars cents -- string )
+: format-money ( dollars cents -- string )
     [ number>string ] bi@
     [ <reversed> 3 group "," join <reversed> ]
     [ 2 CHAR: 0 pad-head ] bi* "." glue ;
 
-: money>string ( object -- string )
-    dollars/cents (money>string) currency-token get prefix ;
+PRIVATE>
+
+: money>string ( number -- string )
+    dollars/cents format-money currency-token get prefix ;
 
-: money. ( object -- ) money>string print ;
+: money. ( number -- ) money>string print ;
 
 ERROR: not-an-integer x ;
 
+<PRIVATE
+
+: split-decimal ( str -- neg? dollars cents )
+    "." split1 [ "-" ?head swap ] dip ;
+
 : parse-decimal ( str -- ratio )
-    "." split1
-    [ "-" ?head swap ] dip
-    [ [ "0" ] when-empty ] bi@
+    split-decimal [ [ "0" ] when-empty ] bi@
     [
         [ dup string>number [ nip ] [ not-an-integer ] if* ] bi@
-    ] keep length
-    10^ / + swap [ neg ] when ;
+    ] keep length 10^ / + swap [ neg ] when ;
+
+PRIVATE>
 
 SYNTAX: DECIMAL: scan-token parse-decimal suffix! ;