read transforms textual Clojure syntax from an input stream into a data structure, which may represent either data or executable code. In a REPL, it obtains the next form before eval processes it; clojure.main/repl can replace this reader to support a different input language. section 17.0 section 22.4
The reader’s practical contract includes:
- Accept a java.io.PushbackReader or subclass; calling read without an explicit stream reads from *in*. section 17.1
- Return the next parsed form, while supporting :eof to choose the result when no form remains. section 17.1
- Control reader conditionals with :read-cond set to :allow or :preserve, and select a platform with :features. section 17.1
- Treat #= specially according to *read-eval*; bind it to false to reject evaluation or :unknown to reject reading. section 17.1
Replacing the REPL reader
A custom calculator REPL supplies :read with a function receiving request-prompt and request-exit. It skips whitespace at line boundaries, reads a line, and returns a regex match such as ["2*3" "2" "*" "3"]. A matching :eval function converts the operands and applies the selected operator, producing 6. section 22.4
