-;   Copyright (c) Rich Hickey. All rights reserved.
-;   The use and distribution terms for this software are covered by the
-;   Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
-;   which can be found in the file epl-v10.html at the root of this distribution.
-;   By using this software in any fashion, you are agreeing to be bound by
-;   the terms of this license.
-;   You must not remove this notice, or any other, from this software.
+                                        ;   Copyright (c) Rich Hickey. All rights reserved.
+                                        ;   The use and distribution terms for this software are covered by the
+                                        ;   Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
+                                        ;   which can be found in the file epl-v10.html at the root of this distribution.
+                                        ;   By using this software in any fashion, you are agreeing to be bound by
+                                        ;   the terms of this license.
+                                        ;   You must not remove this notice, or any other, from this software.
 
 (ns cljs.core)
 

    (irest coll)))

#_(defn conj
  ([coll x]
     (if coll (iconj coll x) '(x))))

(defn reduce
  "f should be a function of 2 arguments. If val is not supplied,

  "Returns a new seq where x is the first element and seq is the rest."
  [first rest]
  (new Cons nil first rest))

(comment
  (use 'cljs.compiler)

  (import '[javax.script ScriptEngineManager])

  (def jse (-> (ScriptEngineManager.) (.getEngineByName "JavaScript")))
  (.eval jse bootjs)

  (defmacro js [form]
    `(emit (analyze {:ns (@namespaces 'cljs.user) :context :statement :locals {}} '~form)))

  (defn jseval [form]
    (let [js (emits (analyze {:ns (@namespaces 'cljs.user) :context :expr :locals {}}
                             form))]
      ;;(prn js)
      (.eval jse (str "print(" js ")"))))

  (with-open [r (PushbackReader. (clojure.java.io/reader "src/cljs/cljs/core.cljs"))]
    (dorun (map-indexed #(do jseval (take-while identity (repeatedly #(read r false nil))))))
    (jseval '(ifirst (irest (cons 1 (cons 2 nil))))))
