Commits

Miki Tebeka  committed f030f69

Initial eval

  • Participants
  • Parent commits 972e20f

Comments (0)

Files changed (1)

File src/dr_evil.clj

-(ns dr.evil)
+(ns dr.evil
+  (:use [clojure.contrib.json :only (json-str)]))
 
 (defn input-page []
   (slurp "src/index.html"))
 
 (defn eval-expr [expr]
-  (
+  (try
+    (let [result (load-string (str "(in-ns 'dr.evil) " expr))]
+      { :result (with-out-str (println result)) :error false })
+    (catch Exception e
+      (let [result (with-out-str (.printStackTrace e))]
+        { :result result :error true }))))
 
 (defn evil [params]
-  (let [expr (params "expr")]
-    (
+  (json-str (eval-expr (params "expr"))))
 
-(defroutes handler
+(defroutes app
   (GET "/" [] (input-page))
   (POST "/" {params :params} (evil params))
   (ANY "/*" [path] (redirect "/"))