I'm trying to create an HTTP server that is essentially a clojure REPL with some integration into some classes on the server's classpath. I've got something working, but I noticed some things that made me realize I don't quite understand the scope of namespaces/imports in clojure when eval'ing. If anyone can shed some light on what's happening and why, it would be great.
I'm using compojure to do my HTTP and the server right now looks like: (ns my.namespace.hello-world (:use compojure) (:use clojure.contrib.duck-streams) (:use clojure.contrib.json.write) (:import java.io.InputStreamReader) (:import java.io.PushbackReader) (:import (org.joda.time Interval DateTime))) (defroutes evallerificator (POST "/1.0/cloj" (eval (read (PushbackReader. (InputStreamReader. (request :body)))))) (GET "/" (html [:h1 "Hello World"])) (ANY "*" (page-not-found))) (run-server {:port 43034} "/*" (servlet evallerificator)) This works if I curl something like: curl -v 'http://localhost:43034/1.0/cloj' -H 'content-type: application/clojure' -d '(str (+ 1 2))' But, if I want to, say, output something in JSON format I have to write curl 'http://localhost:43034/1.0/cloj' -H 'content-type: application/clojure' -d '(clojure.contrib.json.write/json-str {:howdy ["hi" 1 2 3]})' {"howdy":["hi",1,2,3]} If I do just curl 'http://localhost:43034/1.0/cloj' -H 'content-type: application/clojure' -d '(json-str {:howdy ["hi" 1 2 3]})' I get this exception java.lang.Exception: Unable to resolve symbol: json-str in this context (NO_SOURCE_FILE:0) Something like this curl -v 'http://localhost:43034/1.0/cloj' -H 'content-type: application/clojure' -d "(require 'clojure.contrib.json.write) (json-str {:howdy [\"hi\" 1 2 3]})" Doesn't work because I'm only read/eval'ing one thing. My goal is to be able to use things on the classpath from the clojure code that I pass in. It would be nice if I had control of what someone could require/use, but at this point I'm willing to settle for access to anything and everything on the classpath. Any help is appreciated. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---