]> gitweb.factorcode.org Git - factor.git/commitdiff
prettyprint: fix .b, .o, and .h for negative numbers.
authorJohn Benediktsson <mrjbq7@gmail.com>
Sun, 11 Jun 2017 17:57:01 +0000 (10:57 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Sun, 11 Jun 2017 17:57:01 +0000 (10:57 -0700)
Also makes these useful for nested printing in different number bases.

basis/prettyprint/prettyprint.factor

index 6323d05ea43261a4967b740ff0a319f979091841..46b3df664119c6c3cecb34014abb9e9139b5fc38 100644 (file)
@@ -38,9 +38,9 @@ IN: prettyprint
 : error-in-pprint ( obj -- str )
     class-of name>> "~pprint error: " "~" surround ;
 
-: .b ( n -- ) >bin "0b" prepend print ;
-: .o ( n -- ) >oct "0o" prepend print ;
-: .h ( n -- ) >hex "0x" prepend print ;
+: .b ( n -- ) 2 number-base [ . ] with-variable ;
+: .o ( n -- ) 8 number-base [ . ] with-variable ;
+: .h ( n -- ) 16 number-base [ . ] with-variable ;
 
 : stack. ( seq -- )
     [