chapter seventeen

17 Evaluation

 

The functions illustrated in this section are at the heart of the Read, Eval, Print, Loop (REPL for short). When you open the Clojure REPL, you’re welcomed by a prompt waiting for a form to evaluate. That’s a call to read using the standard input as argument. After hitting the return key, eval analyzes the forms and emits bytecode that is put into execution. The result is printed on the screen and the loop start again. But even when you are not using the REPL, Clojure uses the same functions extensively to run a program. There are three main families of functions dedicated to evaluation (with some overlapping):

17.1  read and read-string

17.1.1  read

read transforms a string (in this case a character stream) into the corresponding data structures, following the rules of the Clojure syntax. The character stream should be an instance of java.io.PushbackReader or subclasses. The easiest way to test the function is without arguments, forcing it to use the dynamic var in as input:

17.1.2  read-string

17.2  eval

17.3  test and assert

17.4  load, load-file, load-reader and load-string

17.4.1  load

17.4.2  load-file

17.4.3  load-string

17.4.4  load-reader

17.5  compile

17.6  clojure.edn/read and clojure.edn/read-string

17.7  tagged-literal and tagged-literal?

17.8  default-data-readers