clojure

Shantanu 2026-03-05T05:08:08.644489Z

I'm currently working on bringing jank's read-string to feature parity with Clojure. I'm trying to understand what happens when clojure.core/*read-eval* is set to false. According to (doc *read-eval*),

when set to logical false in the thread-local binding, the eval reader (#=) and record/type literal syntax are disabled in read/load.
I didn't know there was an option to execute code at read time this way, and it behaves in "interesting" ways:
user=> #=(* 2 21)
42

user=> #=(reduce + (take 5 (range 5))) ;; Can't say I understand this.
(0 1 2 3 4)

user=> #=(reduce :k)                   ;; Wasn't expecting it to resolve the var at read/parse time.
Syntax error reading source at (REPL:33:14).
Wrong number of args (1) passed to: clojure.core/reduce
I'm trying to find documentation on this feature, but haven't been able to find it. I've only checked the https://clojure.org/reference/reader & https://clojure.org/reference/evaluation docs so far. Can someone please point me in the right direction? Otherwise I'll just have to check the source code but I'd rather understand the intent than the implementation 🙂.

Shantanu 2026-03-05T15:25:13.488519Z

Thanks, Alex! I'll give this more thought, but probably won't think about this too heavily in my read-string work 🤔.

Alex Miller (Clojure team) 2026-03-05T05:46:38.704739Z

there is no documentation on it as it is not an official feature

Alex Miller (Clojure team) 2026-03-05T06:01:59.409009Z

the eval reader reads, then evals (at read time). It's used in a few special cases to invoke internal Clojure paths to roundtrip data structures from printing (vars and sorted sets and maps):

user=> (binding [*print-dup* true] (pr-str #'read))
"#=(var clojure.core/read)"
user=> (binding [*print-dup* true] (pr-str (sorted-set 1)))
"#=(clojure.lang.PersistentTreeSet/create [1])"
the other "eval" type feature in the reader is the Java constructor reader:
user=> #java.util.Date[1772690057789]
#inst "2026-03-05T05:54:17.789-00:00"

👍 1
👀 1