 ;;todo - move to core.cljs, using js
 (def ^String bootjs "
 //goog.provide should do this for us
-cljs = {}
-cljs.core = {}
-cljs.user = {}
+//cljs = {}
+//cljs.core = {}
+//cljs.user = {}
+goog.provide('cljs.core');
+goog.provide('cljs.user');
 cljs.core.truth_ = function(x){return x != null && x !== false;}
 cljs.core.fnOf_ = function(f){return (f instanceof Function?f:f.cljs$core$Fn$invoke);}")
 

  (let [jse (-> (javax.script.ScriptEngineManager.) (.getEngineByName "JavaScript"))
        base (io/resource "goog/base.js")]
    (assert base "Can't find goog/base.js in classpath")
    (with-open [r (io/reader base)]
      (.eval jse r))
    (.eval jse bootjs)
    {:jse jse}))

(defn repl
  [repl-env]
  (prn "Type: " :cljs/quit " to quit")
  (binding [*cljs-ns* 'cljs.user]
    (let [env {:context :statement :locals {}}]
      (loop []
        (print (str "ClojureScript:" *cljs-ns* "> "))
        (flush)

           (= form :cljs/quit) :quit
           
           (and (seq? form) (= (first form) 'in-ns))
           (do (set! *cljs-ns* (second (second form))) (newline) (recur))

           (and (seq? form) ('#{load-file clojure.core/load-file} (first form)))
           (do (load-file jse (second form)) (newline) (recur))
           
           :else
           (let [ret (eval1 jse (assoc env :ns (@namespaces *cljs-ns*)) form)]
             (prn ret)
             (recur))))))))

(comment

;;the new way - use the REPL!!
(require '[cljs.compiler :as comp])
(def jse (comp/repl-env))  
(comp/repl jse)
(+ 1 2)
(in-ns 'cljs.core)
;;hack on core


;;OLD way, don't you want to use the REPL? 
(in-ns 'cljs.compiler)
(import '[javax.script ScriptEngineManager])
(def jse (-> (ScriptEngineManager.) (.getEngineByName "JavaScript")))
