Reputation: 5567
I'd like to send a clojure expression in a string to be evaluated at the receiver, which might be a web service written in compojure. For example, suppose I have the string "(* 7 6)", which I'd like to turn into '(* 7 6), which I can then pass to eval and get 42. This operation is trivial in JavaScript, but not quite sure how to do it in clojure. Hints?
Upvotes: 3
Views: 318
Reputation: 5619
This should do the trick:
(eval (read-string "(* 7 6)")) ;; 42
Or, for short:
(load-string "(* 7 6)") ;; 42
Upvotes: 5