+(defun code (&rest args)
+ (mapconcat (lambda (arg)
+ (cond
+ ((null arg) "")
+ ((integerp arg) (integer-to-string arg))
+ ((stringp arg) arg)
+ (t (error "Unknown argument."))))
+ args))
+
+;;; Wrap X with a Javascript code to convert the result from
+;;; Javascript generalized booleans to T or NIL.
+(defun js!bool (x)
+ (code "(" x "?" (ls-compile t) ": " (ls-compile nil) ")"))
+
+;;; Concatenate the arguments and wrap them with a self-calling
+;;; Javascript anonymous function. It is used to make some Javascript
+;;; statements valid expressions and provide a private scope as well.
+;;; It could be defined as function, but we could do some
+;;; preprocessing in the future.
+(defmacro js!selfcall (&body body)
+ `(code "(function(){" *newline* (indent ,@body) "})()"))
+
+;;; Like CODE, but prefix each line with four spaces. Two versions
+;;; of this function are available, because the Ecmalisp version is
+;;; very slow and bootstraping was annoying.
+
+#+ecmalisp
+(defun indent (&rest string)
+ (let ((input (apply #'code string)))
+ (let ((output "")
+ (index 0)
+ (size (length input)))
+ (when (plusp (length input)) (concatf output " "))
+ (while (< index size)
+ (let ((str
+ (if (and (char= (char input index) #\newline)
+ (< index (1- size))
+ (not (char= (char input (1+ index)) #\newline)))
+ (concat (string #\newline) " ")
+ (string (char input index)))))
+ (concatf output str))
+ (incf index))
+ output)))
+
+#+common-lisp
+(defun indent (&rest string)
+ (with-output-to-string (*standard-output*)
+ (with-input-from-string (input (apply #'code string))
+ (loop
+ for line = (read-line input nil)
+ while line
+ do (write-string " ")
+ do (write-line line)))))
+
+