(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."
(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.")