January 2017
Intermediate to advanced
565 pages
13h 46m
English
Let's have a look at how code can be parsed and evaluated in Clojure. The most elementary way to convert text into an expression is by using the read function. This function accepts a java.io.PushbackReader instance as its first argument, as shown here:
user> (read (-> "(list 1 2 3)" .toCharArray java.io.CharArrayReader. java.io.PushbackReader.)) (list 1 2 3)
These examples can be found in src/m_clj/c4/read_and_eval.clj of the book's source code.
In this example, a string containing a valid expression is first converted into an instance of java.io.PushbackReader and then passed to the read function. It seems like a lot of unnecessary work to read a string, but it is due to the fact that the read function deals ...
Read now
Unlock full access