]> gitweb.factorcode.org Git - factor.git/commitdiff
math.parser: simplify { integer ratio } >base.
authorJohn Benediktsson <mrjbq7@gmail.com>
Sun, 19 Jul 2015 23:45:46 +0000 (16:45 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Sun, 19 Jul 2015 23:57:45 +0000 (16:57 -0700)
core/math/parser/parser.factor

index 3261bcf30caa5f9179fc34bd7c306f939451da27..3bc8444f80d27e479f6e0ae2ae0fca8028b7dc47 100644 (file)
@@ -420,24 +420,19 @@ GENERIC# >base 1 ( n radix -- str )
 : >hex ( n -- str ) 16 >base ; inline
 
 M: integer >base
-    over 0 = [
-        2drop "0"
-    ] [
-        over 0 > [
-            positive>base
-        ] [
-            [ neg ] dip positive>base CHAR: - prefix
-        ] if
-    ] if ;
+    {
+        { [ over 0 = ] [ 2drop "0" ] }
+        { [ over 0 > ] [ positive>base ] }
+        [ [ neg ] dip positive>base CHAR: - prefix ]
+    } cond ;
 
 M: ratio >base
-    [ [ 0 < ] [ abs 1 /mod ] bi ]
-    [ [ positive>base ] curry ] bi*
-    [
-        [ [ numerator ] [ denominator ] bi ] dip bi@ "/" glue
-    ] keep rot [ drop ] [
-        swap call pick "-" "+" ? rot 3append
-    ] if-zero swap [ CHAR: - prefix ] when ;
+    [ >fraction [ /mod ] keep ] [ [ >base ] curry tri@ ] bi*
+    "/" glue over first-unsafe {
+        { CHAR: 0 [ nip ] }
+        { CHAR: - [ append ] }
+        [ drop "+" glue ]
+    } case ;
 
 <PRIVATE