Fixed nary comparison operators (ex: (< 1 2 3) should translate to (1
[clinton/parenscript.git] / src / compilation-interface.lisp
index 3c7ea77..0fcaa27 100644 (file)
@@ -5,8 +5,13 @@
 (defmacro ps (&body body)
   "Given Parenscript forms (an implicit progn), compiles those forms
 to a JavaScript string at macro-expansion time."
-  `(concatenate 'string ,@(parenscript-print (compile-parenscript-form `(progn ,@body) :expecting :statement))))
-
+  (let ((s (gensym)))
+    `(with-output-to-string (,s)
+       ,@(mapcar (lambda (x)
+                   `(write-string ,x ,s))
+                 (parenscript-print
+                  (compile-parenscript-form `(progn ,@body)
+                                            :expecting :statement))))))
 (defun ps* (&rest body)
   "Compiles BODY to a JavaScript string.
 Body is evaluated."
@@ -25,12 +30,8 @@ Body is evaluated."
 
 (defun compiled-form-to-string (ps-compiled-form)
   (with-output-to-string (s)
-    (mapc (lambda (x)
-            (princ (if (stringp x)
-                       x
-                       (eval x))
-                   s))
-          (parenscript-print ps-compiled-form))))
+    (dolist (x (parenscript-print ps-compiled-form))
+      (write-string (if (stringp x) x (eval x)) s))))
 
 (defvar *js-inline-string-delimiter* #\"
   "Controls the string delimiter char used when compiling Parenscript in ps-inline.")