]> gitweb.factorcode.org Git - factor.git/commitdiff
Update math.english with faster algorithm and new combinators
authorAaron Schaefer <aaron@elasticdog.com>
Tue, 16 Dec 2008 02:49:31 +0000 (21:49 -0500)
committerAaron Schaefer <aaron@elasticdog.com>
Tue, 16 Dec 2008 02:49:31 +0000 (21:49 -0500)
extra/math/text/english/english.factor

index 41f19b9b07b7e2a93d53a27006d6bf5d5635a46c..643fc3ae051bc94c46327d9b4185e6284655eb38 100755 (executable)
@@ -32,23 +32,22 @@ SYMBOL: and-needed?
     0 < "Negative " "" ? ;
 
 : 3digit-groups ( n -- seq )
-    number>string <reversed> 3 <groups>
-    [ reverse string>number ] map ;
+    [ dup 0 > ] [ 1000 /mod ] [ ] produce nip ;
 
 : hundreds-place ( n -- str )
-    100 /mod swap dup zero? [
+    100 /mod over 0 = [
         2drop ""
     ] [
-        small-numbers " Hundred" append
-        swap zero? [ " and " append ] unless
+        [ small-numbers " Hundred" append ] dip
+        0 = [ " and " append ] unless
     ] if ;
 
 : tens-place ( n -- str )
     100 mod dup 20 >= [
         10 /mod [ tens ] dip
-        dup zero? [ drop ] [ "-" swap small-numbers 3append ] if
+        dup 0 = [ drop ] [ small-numbers "-" glue ] if
     ] [
-        dup zero? [ drop "" ] [ small-numbers ] if
+        dup 0 = [ drop "" ] [ small-numbers ] if
     ] if ;
 
 : 3digits>text ( n -- str )
@@ -59,15 +58,15 @@ SYMBOL: and-needed?
     [ " " glue ] unless-empty ;
 
 : append-with-conjunction ( str1 str2 -- newstr )
-    over length zero? [
+    over length 0 = [
         nip
     ] [
-        and-needed? get " and " ", " ? rot 3append
-        and-needed? off
+        swap and-needed? get " and " ", " ?
+        glue and-needed? off
     ] if ;
 
 : (recombine) ( str index seq -- newstr )
-    2dup nth zero? [
+    2dup nth 0 = [
         2drop
     ] [
         text-with-scale append-with-conjunction