Welcome! Please see the About page for a little more info on how this works.

+3 votes
in Syntax and reader by
retagged by

When setting *default-data-reader-fn* to tagged-literal (as suggested in https://clojure.org/reference/reader#_default_data_reader_function) in a REPL like so:

user=> (set! *default-data-reader-fn* tagged-literal)

As advertised, the REPL can now read unknown tagged literals, e.g.:

user=> #foo 123
#foo 123

However, it fails when embedded in an expresson like so:

user=> (prn #foo 123)
Syntax error compiling fn* at (REPL:1:1).
Can't embed object in code, maybe print-dup not defined: clojure.lang.TaggedLiteral@34b5d34f

The hint in the error message works indeed, so when I provide:

user=> (defmethod print-dup clojure.lang.TaggedLiteral [tl w] (print-method tl w))

The REPL can now successfully read and eval the previous expression:

user=> (prn #foo 123)
#foo 123

Should the print-dup implementation for clojure.lang.TaggedLiteral perhaps be provided by default?

1 Answer

+2 votes
selected by
Best answer