How can I add imports to an "eval"ed piece of clojure code?

Posted by Zubair on Stack Overflow See other posts from Stack Overflow or by Zubair
Published on 2010-12-26T13:33:56Z Indexed on 2010/12/26 17:54 UTC
Read the original article Hit count: 175

Filed under:

I would like to evaluate some clojure code entered by users interactively, and I would like to "use" certain namespaces and "import" certain Java classes as well. I end up running the code using:

(defn execute-command [string-command]
    let [
        code-with-context  (add-code-context string-command)
        result             (eval(read-string code-with-context))
        ]

        result
)

My question is how can I program "add-code-context" to add the required context to the code in "string-command"?

© Stack Overflow or respective owner

Related posts about clojure