Miki Tebeka avatar Miki Tebeka committed e448485

Namespaces works!

Comments (0)

Files changed (1)

   (:use [clojure.stacktrace :only (print-stack-trace)])
   (:use [clojure.contrib.json :only (json-str)]))
-; FIXME: Give use ability to change namespace
-(defn wrapped-expr [expr]
-  (str "(binding [*print-length* 100] " expr ")"))
+(def *user-ns* (atom *ns*))
+(defn set-ns! [new-ns]
+  (swap! *user-ns* (constantly (create-ns (symbol new-ns)))))
+(defn eval-in-user-ns [expr]
+  (binding [*ns* @*user-ns*]
+    (refer 'clojure.core)
+    (eval (read-string expr))))
 (defn eval-expr [expr]
-    (let [result (load-string (wrapped-expr expr))]
+    (let [result (eval-in-user-ns expr)]
       { :result (with-out-str (println result)) :error false })
     (catch Exception e
       (let [result (with-out-str (print-stack-trace e))]
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.