How do you evaluate a string as a clojure expression?

℡╲_俬逩灬. 提交于 2019-11-28 10:41:19
(load-string "(+ 1 2)")
user> (eval (read-string "(+ 1 2)"))
3

You probably shouldn't ever need to do this. Macros and fns make this kind of thing unnecessary 99% of the time. This is quite brittle, and can be unsafe if these strings are coming from user input, and so on.

How similar does it have to be? Clojure's eval works on lists, so:

(eval (list + 1 2)) #=> 3
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!