Question

How would I get something similar to the following?:

(evaluate-text "(+ 1 2)")  ; resolves to 3
Was it helpful?

Solution

(load-string "(+ 1 2)")

OTHER TIPS

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top