Clojure how to eval code from a string

I have a string of Clojure code comes from another text file, its actually a DSL language which can be embedded in another file. I use a special delimiter to specify the start and end of a piece of Clojure code. When we process the text file, we will extract the Clojure code from the file and evaluate it at runtime. This is especially useful when you want to add some instructions to the logic of the processing of the document, which then can be done programmatically in the syntax of DSL.

Of course you can design a simple text format and then write an interpreter for it, like what Ant did. Ant uses XML document to let user specify instructions for build process. LISP can do the same thing, act as a configuration file, but you can also do programming in it. The newest build Gradle already introduce this philosophy, a configuration file is a DSL programming language.

There two functions in Clojure can evaluate code from a string: read-string, load-string.

The read-string assumes the string only contains one statement, if you provide multiple statements, only the first one is evaluated. This maybe a little confusion for many people, because a string can be a block of text, this function may be designed to use in a REPL, to evaluate one liner of Clojure code.

 
user> (read-string " (+ 2 3)")
(+ 2 3)
user> (read-string " (+ 2 3) (- 3 4)")
(+ 2 3)
 

To evaluate a block of text, use load-string, it acts like load-file, just the content comes from a string, not a file.

 
(eval (load-string clojurecode))