syntax | since v0.0-1853 | in clojure | Edit |
A proper definition for something that cannot be read.
#<...>
When certain values cannot be printed to a REPL using some literal syntax form,
it wraps a description of its value in a form defined as unreadable, #<>
. A
reader error will be thrown if this value is fed back into the REPL.
For example, (atom 42)
will print #<Atom: 42>
when evaluated in a REPL.
This communicates a human-readable form that is not intended to be reproduce
its value.
Oftentimes, evaluating JavaScript objects in a REPL will print the result
of its .toString
method inside the unreadable form #<>
.
Unreadable forms will throw an exception when read:
#
;; clojure.lang.ExceptionInfo: Unreadable form
You can create an unreadable form for a custom type:
(deftype Foo [])
(Foo.)
;;=> #<[object Object]>
(deftype Foo [x]
Object
(toString [_]
(str "Foo: " x)))
(Foo. 1)
;;=> #
Some examples of unreadable JavaScript values:
Math/sin
;;=> #
js/console
;;=> #<[object Object]>
(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))