Character printing
authorDavid Vázquez <davazp@gmail.com>
Thu, 2 May 2013 15:03:39 +0000 (16:03 +0100)
committerDavid Vázquez <davazp@gmail.com>
Thu, 2 May 2013 15:03:39 +0000 (16:03 +0100)
src/compiler.lisp
src/print.lisp

index dec5eaa..eadbf39 100644 (file)
     "String.fromCharCode(x)"))
 
 (define-builtin characterp (x)
-  (js!bool (code "(typeof(" x ") == \"string\")")))
+  (js!bool
+   (js!selfcall
+     "var x = " x ";" *newline*
+     "return (typeof(" x ") == \"string\") && x.length == 1;")))
 
 (define-builtin char-to-string (x)
   (type-check (("x" "number" x))
index 919ab3d..dfa1b69 100644 (file)
                      ":" name)))))
     ((integerp form) (integer-to-string form))
     ((floatp form) (float-to-string form))
+    ((characterp form)
+     (concat "#\\" 
+             (case form
+               (#\newline "newline")
+               (#\space "space")
+               (otherwise (string form)))))
     ((stringp form) (concat "\"" (escape-string form) "\""))
     ((functionp form)
      (let ((name (oget form "fname")))