Pretty weird. I can replicate your error but can't explain it. I guess there's an interaction between eval and the way that the reader knows about namespaces, with the creation of a new namespace during a call to eval not making it available later in the same call... I'm not at all clear about how namespaces are managed so I don't know for sure.
However, if you can separate the require from the rest of the user's string then you can work around this.
First of all, if you know ahead of time what libs will be required then you can just require them in the normal way, without evaling strings, etc.
But if for some reason the lib name has to be coming in as a string at runtime then you can do something like this:
(def expr1 "(require '[foo :as f])")
(def expr2 "(f/bar a)")
(do (eval (read-string expr1))
((eval (list 'fn '[a] (read-string expr2))) 3))
Here my foo library is just:
(ns foo)
(defn bar [x] (+ x x))
And running the "do" call above raises no exception and returns 6.
-Lee
--
Lee Spector, Professor of Computer Science
Cognitive Science, Hampshire College
893 West Street, Amherst, MA 01002-3359
lspe...@hampshire.edu,
http://hampshire.edu/lspector/
Phone:
413-559-5352, Fax:
413-559-5438