#= eval

syntaxsince v0.0-1853 in clojureEdit

The ability to evaluate forms at reader-time should be ignored in ClojureScript.

  • #=...

Details:

Allows the reader to evaluate the following form.

This feature is carried from tools.reader is not intended for use in ClojureScript, though it works for basic forms not using symbols.


Examples:

#=123
;;=> 123

#="foo"
;;=> foo

(def foo 1)
#='foo
;;=> 1

The following is the output for the ClojureScript compiler on the JVM:

#=(+ 1 2)
;; java.lang.RuntimeException: Unable to resolve symbol: + in this context

#=(clojure.core/+ 1 2)
;;=> 3

Reader code @ tools.reader:src/main/clojure/clojure/tools/reader.clj
(defn- read-eval
  [rdr _ opts pending-forms]
  (when-not *read-eval*
    (err/reader-error rdr "#= not allowed when *read-eval* is false"))
  (eval (read* rdr true nil opts pending-forms)))

Reader table @ tools.reader:src/main/clojure/clojure/tools/reader.clj
(defn- dispatch-macros [ch]
  (case ch
    \^ read-meta                ;deprecated
    \' (wrapping-reader 'var)
    \( read-fn
    \= read-eval
    \{ read-set
    \< (throwing-reader "Unreadable form")
    \" read-regex
    \! read-comment
    \_ read-discard
    \? read-cond
    \: read-namespaced-map
    \# read-symbolic-value
    nil))