+ ((integerp sexp) (format nil "~a" sexp))
+ ((stringp sexp) (format nil "\"~a\"" sexp))
+ ((listp sexp) (concat "[" (join (mapcar 'lisp->js sexp) ",") "]"))))
+
+(define-compilation quote (sexp)
+ (lisp->js sexp))
+
+(define-compilation debug (form)
+ (format nil "console.log(~a)" (ls-compile form env fenv)))
+
+(define-compilation while (pred &rest body)
+ (format nil "(function(){while(~a){~a}})() "
+ (ls-compile pred env fenv)
+ (ls-compile-sexps body env fenv)))
+
+(defmacro eval-when-compile (&body body)
+ `(eval-when (:compile-toplevel :execute)
+ ,@body))
+
+(define-compilation eval-when-compile (&rest body)
+ (eval (cons 'progn body)))
+
+;;; aritmetic primitives
+(define-compilation + (x y)
+ (concat "((" (ls-compile x env fenv) ") + (" (ls-compile y env fenv) "))"))
+
+(define-compilation - (x y)
+ (concat "((" (ls-compile x env fenv) ") - (" (ls-compile y env fenv) "))"))
+
+(define-compilation * (x y)
+ (concat "((" (ls-compile x env fenv) ") * (" (ls-compile y env fenv) "))"))
+
+(define-compilation / (x y)
+ (concat "((" (ls-compile x env fenv) ") / (" (ls-compile y env fenv) "))"))
+
+(define-compilation = (x y)
+ (concat "((" (ls-compile x env fenv) ") == (" (ls-compile y env fenv) "))"))
+
+
+(defun %compile-defvar (name)
+ (push (make-var-binding name) *env*)
+ (format nil "var ~a" (lookup-variable name *env*)))
+
+(defun %compile-defun (name)
+ (push (make-func-binding name) *fenv*)
+ (format nil "var ~a" (lookup-variable name *fenv*)))
+
+(defun compile-funcall (name args env fenv)
+ (format nil "~a(~{~a~^, ~})"
+ (lookup-function name fenv)
+ (mapcar (lambda (x) (ls-compile x env fenv)) args)))
+
+(defun ls-compile (sexp &optional env fenv)
+ (cond
+ ((symbolp sexp) (lookup-variable sexp env))
+ ((integerp sexp) (format nil "~a" sexp))
+ ((stringp sexp) (format nil "\"~a\"" sexp))