Add missing clean targets in 5 impls.
[jackhill/mal.git] / ps / printer.ps
index 3062e2d..817bece 100644 (file)
         (\))
         concatenate
     }{ /integertype obj type eq { % if number
-        /slen obj 10 add log ceiling cvi def
+        /slen
+          obj abs 1 max log floor cvi 1 add % positive size
+          obj 0 lt { 1 add } if % account for sign
+        def
         obj 10 slen string cvrs
     }{ /stringtype obj type eq { % if string
-        print_readably {
-            (")
-            obj (\\) (\\\\) replace
-                (") (\\") replace
-            (") concatenate concatenate
-        }{
-            obj
+        obj length 0 gt { % if string length > 0
+            obj 0 get 127 eq { %if starts with 0x7f (keyword)
+                obj dup length string copy
+                dup 0 58 put % 58 is ':'
+            }{ print_readably {
+                (")
+                obj (\\) (\\\\) replace
+                    (") (\\") replace
+                    (\n) (\\n) replace
+                (") concatenate concatenate
+            }{
+                obj
+            } ifelse } ifelse
+        }{ % else empty string
+            print_readably {
+                ("")
+            }{
+                obj
+            } ifelse
         } ifelse
     }{ null obj eq { % if nil
         (nil)