clojure - eval code in different namespace

后端 未结 4 2150
情深已故
情深已故 2021-02-08 17:28

I\'m coding something like REPL Server. Request from users evaluates in such function:

(defn execute [request]
  (str (try
          (eval (read-string request))         


        
4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-08 18:18

    You can write a macro that mimics

    (defmacro my-eval [s] `~(read-string s))
    

    It works better that eval because the symbol resolution of s occurs in the context that calls my-eval. Thanks to @Matthias Benkard for the clarifications.

提交回复
热议问题