<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Clojure Q&amp;A - Recent questions tagged tagged literal</title>
<link>https://ask.clojure.org/index.php/tag/tagged+literal</link>
<description></description>
<item>
<title>Aliased namespace in tagged literal</title>
<link>https://ask.clojure.org/index.php/14829/aliased-namespace-in-tagged-literal</link>
<description>&lt;p&gt;&lt;strong&gt;Set up&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Tagged literals are defined by setting a namespaced symbol in &lt;code&gt;data_readers.clj&lt;/code&gt; (or &lt;code&gt;data_readers.cljc&lt;/code&gt;). At load, Clojure merges all of the maps defined in &lt;code&gt;data_readers.clj(c)&lt;/code&gt; files found on the classpath into a single map. At read time, the symbol following a &lt;code&gt;#&lt;/code&gt; is checked in the merged data readers map, which determines which var to call with the contents of the following form.&lt;/p&gt;
&lt;p&gt;For example, &lt;code&gt;#foo/bar [1 2 3]&lt;/code&gt; leads to the reader calling the equivalent of &lt;code&gt;(get *data-readers* 'foo/bar)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Problem statement&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The tag of a tagged literal must be determined when it is created. The namespace of the chosen tag is set and cannot be changed by a user. Unlike a fully qualified symbol with an aliased namespace, a tagged literal must what was chosen by the author.&lt;/p&gt;
&lt;p&gt;As an author of tagged literals, I want to write tags that will not clash with other tags by giving them complex/deep namespaces. For example, &lt;code&gt;{noahtheduke.lazytest/expect noahtheduke.lazytest/expect}&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;As a user of tagged literals, I want to alias the namespace of tags and use it in my code. For example:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;;; in src/data_readers.clj
{noahtheduke.lazytest/expect noahtheduke.lazytest/expect}

;; in test/noahtheduke/example_project/main-test.clj
(ns noahtheduke.example-project.main-test
  (:require
   [noahtheduke.lazytest :as-alias lt]
   [noahtheduke.lazytest.core :refer [defdescribe it]]))

(defdescribe some-test
  (it &quot;works&quot;
    #lt/expect (= 1 2)))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;EDN&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This is not related to edn at all and any potential change will be to Clojure itself.&lt;/p&gt;
</description>
<category>Syntax and reader</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14829/aliased-namespace-in-tagged-literal</guid>
<pubDate>Thu, 11 Dec 2025 20:01:16 +0000</pubDate>
</item>
<item>
<title>clojure.edn/read invoke user-supplied reader functions when tagged literal is to be discarded by discard macro</title>
<link>https://ask.clojure.org/index.php/14761/clojure-supplied-functions-tagged-literal-discarded-discard</link>
<description>&lt;p&gt;According to edn-format/edn specification &lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;A reader should not call user-supplied tag handlers during the processing of the element to be discarded.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;But with clojure.edn/read and its derivatives execute provided reader functions under discard tag:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;user=&amp;gt; (clojure.edn/read-string {:readers {'foo (fn [val] (prn &quot;!!!&quot;) val)}} &quot;#_ #foo [1 2 3]&quot;)
&quot;!!!&quot;
Execution error at user/eval216 (REPL:1).
EOF while reading
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The same happen with clojure.core/read and its derivatives:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;user=&amp;gt; (binding [*data-readers* {'foo (fn [val] (prn &quot;!!!&quot;) val)}] (read-string &quot;#_ #foo [1 2 3]&quot;))
&quot;!!!&quot;
Execution error at user/eval146 (REPL:1).
EOF while reading
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I understand that Clojure' reader does not provide explicit description of what is executed during reading out form to be discarded except &quot;The form following #_ is completely skipped by the reader.&quot; but I think it is worth to mention that here.&lt;/p&gt;
&lt;p&gt;After realisation that this post is not qualifies as &quot;ask&quot;&lt;/p&gt;
&lt;p&gt;To summarize:&lt;br&gt;
Is this a bug in clojure edn specification implementation?&lt;br&gt;
Is the edn specification no longer accurate?&lt;/p&gt;
</description>
<category>Syntax and reader</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14761/clojure-supplied-functions-tagged-literal-discarded-discard</guid>
<pubDate>Thu, 20 Nov 2025 14:57:19 +0000</pubDate>
</item>
<item>
<title>Tagged literals in Clojure CLI arguments and deps.edn</title>
<link>https://ask.clojure.org/index.php/13278/tagged-literals-in-clojure-cli-arguments-and-deps-edn</link>
<description>&lt;p&gt;As it stands there is no way for the Clojure CLI to extend the reader with tagged literals for use within arguments or deps.edn.&lt;/p&gt;
&lt;p&gt;I propose that some mechanism for this should be added, which can enable additional tooling to use the intended use case of putting data within aliases in deps.edn where they otherwise would be restricted by data readers.&lt;/p&gt;
&lt;p&gt;An example of a current project which would benefit from this is Codox, which has support for regular expression based filters on namespaces to be documented, however as the default EDN reader does not include support for regular expressions, this feature is unusable.&lt;/p&gt;
&lt;p&gt;If tagged literals support was added to the Clojure CLI, this problem could be resolved by a &lt;code&gt;#jvm/regex&lt;/code&gt; tag or similar being added for that usecase.&lt;/p&gt;
&lt;p&gt;If this feature is added it should also be considered what happens when a deps.edn file or argument to the CLI includes a tagged literal which is not bound in the current invocation.&lt;/p&gt;
&lt;p&gt;There are multiple ways that support could be added to the CLI, and below I present a few of my own thoughts on the matter, but this is not a request for this to be the way that the feature is implemented, just some ideas.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Tagged literals could be added via aliases in the user deps.edn which are then used by default in all projects&lt;/li&gt;
&lt;li&gt;Tagged literals could be specified by an environment variable, which users can then set with direnv or other tooling&lt;/li&gt;
&lt;/ul&gt;
</description>
<category>Clojure CLI</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/13278/tagged-literals-in-clojure-cli-arguments-and-deps-edn</guid>
<pubDate>Tue, 12 Sep 2023 21:02:35 +0000</pubDate>
</item>
<item>
<title>Why can't unknown tagged literals be embedded in expressions when `*default-data-reader-fn*` is set to `tagged-literal`?</title>
<link>https://ask.clojure.org/index.php/13274/unknown-tagged-literals-embedded-expressions-default-literal</link>
<description>&lt;p&gt;When setting &lt;code&gt;*default-data-reader-fn*&lt;/code&gt; to &lt;code&gt;tagged-literal&lt;/code&gt; (as suggested in &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojure.org/reference/reader#_default_data_reader_function&quot;&gt;https://clojure.org/reference/reader#_default_data_reader_function&lt;/a&gt;) in a REPL like so:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;user=&amp;gt; (set! *default-data-reader-fn* tagged-literal)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;As advertised, the REPL can now read unknown tagged literals, e.g.:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;user=&amp;gt; #foo 123
#foo 123
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;However, it fails when embedded in an expresson like so:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;user=&amp;gt; (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
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The hint in the error message works indeed, so when I provide:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;user=&amp;gt; (defmethod print-dup clojure.lang.TaggedLiteral [tl w] (print-method tl w))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The REPL can now successfully read and eval the previous expression:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;user=&amp;gt; (prn #foo 123)
#foo 123
nil
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Should the &lt;code&gt;print-dup&lt;/code&gt; implementation for &lt;code&gt;clojure.lang.TaggedLiteral&lt;/code&gt; perhaps be provided by default?&lt;/p&gt;
</description>
<category>Syntax and reader</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/13274/unknown-tagged-literals-embedded-expressions-default-literal</guid>
<pubDate>Tue, 12 Sep 2023 15:50:14 +0000</pubDate>
</item>
<item>
<title>Why different symbol handling by tagged literals  vs elements (reader vs edn)</title>
<link>https://ask.clojure.org/index.php/13212/different-symbol-handling-tagged-literals-elements-reader</link>
<description>&lt;p&gt;The reader &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojure.org/reference/reader#tagged_literals&quot;&gt;reference docs state&lt;/a&gt; &quot;tagged literals are Clojure’s implementation of edn tagged elements.&quot;&lt;/p&gt;
&lt;p&gt;But the two are different in at least one regard: a symbol produced by a tagged literal will be resolved, but a symbol produced by a tagged element and read by &lt;code&gt;clojure.edn/read-string&lt;/code&gt; will not.&lt;/p&gt;
&lt;p&gt;This means you can get different output if you read EDN containing a given tag vs. if you use the same tag to produce a literal in your source.&lt;/p&gt;
&lt;p&gt;Example:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;data_readers.cj&lt;/code&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;{example/symbolize clojure.core/symbol}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;user&amp;gt; (edn/read-string {:readers {(quote example/symbolize) clojure.core/symbol}}
                       &quot;#example/symbolize\&quot;hello\&quot;&quot;)   
hello
user&amp;gt; #example/symbolize &quot;hello&quot;
Syntax error compiling at (*cider-repl clojure/foragr:localhost:46533(clj)*:0:0).
Unable to resolve symbol: hello in this context
user&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Is there any particular reason for this discrepency? Is there a scenario where it would be good to resolve symbols from a tagged literal? And if so, why not do the same from tagged elements and &lt;code&gt;edn/read-string&lt;/code&gt;?&lt;/p&gt;
</description>
<category>Clojure</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/13212/different-symbol-handling-tagged-literals-elements-reader</guid>
<pubDate>Sun, 27 Aug 2023 21:43:42 +0000</pubDate>
</item>
<item>
<title>request: provide #uri edn extenstion for java.net.URI and goog.Uri out of the box</title>
<link>https://ask.clojure.org/index.php/12274/request-provide-uri-edn-extenstion-for-java-net-uri-and-goog</link>
<description>&lt;p&gt;&lt;strong&gt;Q1: is there a particular reason the &lt;code&gt;#uri&lt;/code&gt; edn extension was not provided in Clojure&lt;/strong&gt;, given that clojure and clojurescript implement &lt;code&gt;clojure.core/uri?&lt;/code&gt; on &lt;code&gt;java.net.URI&lt;/code&gt; and &lt;code&gt;goog.Uri&lt;/code&gt;?&lt;/p&gt;
&lt;p&gt;Here is a gist documenting how to do it, with tests: &lt;a rel=&quot;nofollow&quot; href=&quot;https://gist.github.com/dustingetz/89a8333b8e5bf73b0f527d865d53079a&quot;&gt;HOWTO install #uri reader extension in Clojure/Script&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Despite the instruction that &quot;Reader tags without namespace qualifiers are reserved for Clojure&quot; I thought this was safe, because if Clojure were to eventually provide it then: (1) this impl becomes superseded and should be removed; (2) this impl is intended to be the exact implementation that core would provide.&lt;/p&gt;
&lt;p&gt;However Borkdude pointed out:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;borkdude&lt;/strong&gt; The problem is that you can't easily undo overriding built-in tags if people have data_readers.cljc stuff on their classpath that override&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Dustin Getz&lt;/strong&gt; Ah so if this extension ends up bundled as a transitive dependency in some lib&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;borkdude&lt;/strong&gt; Yes. So even if you wish to remove it, as you know, software isn't killed that easily&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Q2:&lt;/strong&gt; Therefore I request this be considered to someday be provided in core&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Q3:&lt;/strong&gt; Is this the correct impl? (It's my intent to document this once and for all so I appreciate feedback/comments.)&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Q4:&lt;/strong&gt; transit-clj &amp;amp; transit-cljs decline to read java.net.URI and goog.Uri (in disalignment with the &lt;code&gt;clojure.core/uri?&lt;/code&gt; predicate), instead reading as cct.Uri. Why is that?&lt;/p&gt;
</description>
<category>Clojure</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/12274/request-provide-uri-edn-extenstion-for-java-net-uri-and-goog</guid>
<pubDate>Sun, 02 Oct 2022 16:43:07 +0000</pubDate>
</item>
<item>
<title>improve syntax errors on tagged-literals</title>
<link>https://ask.clojure.org/index.php/12256/improve-syntax-errors-on-tagged-literals</link>
<description>&lt;p&gt;When we write a symbol in the UUID literal, the reported error message is wrong&lt;/p&gt;
&lt;p&gt;(as of 1.11.1)&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;clojure -M -e '#uuid id'
Execution error (AssertionError) at clojure.main/main (main.java:40).
Assert failed: (string? form)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It is wrong because&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;It is not an execution error. Should be read or syntax error.&lt;/li&gt;
&lt;li&gt;It does not include any ex-data: &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojure.org/reference/repl_and_main#_error_printing&quot;&gt;https://clojure.org/reference/repl_and_main#_error_printing&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It should be something like this&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Reader error (AssertionError) at clojure.uuid/default-uuid-reader (uuid.clj:12).
Assert failed: (string? form)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A second step improvement could be add spec support to data-literals, as macros do.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Syntax error reading #uuid id at (REPL:1)
id - failed: string? at: [:form]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;From #clojure-dev slack channel&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;Alex: You don’t need anything special there - just an instrumented spec on the data reader fn&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;After run&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(s/fdef clojure.uuid/default-uuid-reader :args (s/cat :form string?))
(clojure.spec.test.alpha/instrument `clojure.uuid/default-uuid-reader)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The message turns into&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Syntax error reading source at (REPL:2:1).
Call to #'clojure.uuid/default-uuid-reader did not conform to spec.
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is a way better message.&lt;/p&gt;
&lt;p&gt;Also, it includes a &lt;code&gt;#:clojure.error{:phase :read-source}&lt;/code&gt; in ex-data.&lt;br&gt;
So the fix could be just add a spec to &lt;code&gt;clojure.uuid/default-uuid-reader&lt;/code&gt;&lt;/p&gt;
</description>
<category>Syntax and reader</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/12256/improve-syntax-errors-on-tagged-literals</guid>
<pubDate>Wed, 28 Sep 2022 13:24:40 +0000</pubDate>
</item>
<item>
<title>Should Clojure automatically load namespaces of vars defined in data_readers.clj?</title>
<link>https://ask.clojure.org/index.php/11286/should-clojure-automatically-namespaces-defined-datareaders</link>
<description>&lt;p&gt;I thought Clojure automatically loads namespaces for vars used to read tagged literals in the source code, but apparently it isn't.&lt;/p&gt;
&lt;p&gt;Given a library that defines data_readers.clj with following content:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;{foo/bar my.library.foo/bar
 foo/baz my.library/baz}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;An attempt to read &lt;code&gt;#foo/bar [1 2 3]&lt;/code&gt; will result in this exception:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Syntax error reading source at (REPL:1:69).
Attempting to call unbound fn: #'my.library.foo/bar
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To avoid this exception you need to &lt;code&gt;require&lt;/code&gt; the library namespace before using reader tags. &lt;/p&gt;
&lt;p&gt;It would be more convenient to be able to use library reader tags just by adding it to the classpath without explicit require step. &lt;/p&gt;
&lt;p&gt;I don't know why it's made this way... &lt;/p&gt;
&lt;p&gt;If the reasoning is clojure.core startup time, perhaps the actual load of the var ns might happen at the first tagged literal read time?&lt;br&gt;
If the reasoning is security implications of unexpected code execution, maybe the behavior of requiring data reader namespaces could be configured with &lt;code&gt;*read-eval*&lt;/code&gt;?&lt;/p&gt;
</description>
<category>Syntax and reader</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/11286/should-clojure-automatically-namespaces-defined-datareaders</guid>
<pubDate>Mon, 22 Nov 2021 14:29:20 +0000</pubDate>
</item>
<item>
<title>Clojurescript core.async go block incorrectly handles records returned from tagged literals</title>
<link>https://ask.clojure.org/index.php/10987/clojurescript-incorrectly-handles-records-returned-literals</link>
<description>&lt;p&gt;In clojurescript, I have a data reader that returns a record from a tagged literal:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(ns x.x)

(defrecord X [y])

(defn make-x [y] (-&amp;gt;X y))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;data_readers.cljc:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;{x x.x/make-x}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This doesn't work correctly inside of go blocks:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(println &quot;outside of go:&quot; #x&quot;a&quot;)
(go
  (println &quot;inside of go:&quot; (&amp;lt;! (go #x&quot;b&quot;))))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Results in:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;outside of go: #x.x.X{:y a}
inside of go: {:y b}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;@hiredman on the clojurians slack pointed out the issue:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;what is happening is here&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/clojure/core.async/blob/master/src/main/clojure/cljs/core/async/impl/ioc_macros.clj#L403&quot;&gt;https://github.com/clojure/core.async/blob/master/src/main/clojure/cljs/core/async/impl/ioc_macros.clj#L403&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;&lt;p&gt;map? is returning true so it is compiling your record as a map&lt;/p&gt;
&lt;/blockquote&gt;
</description>
<category>ClojureScript</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/10987/clojurescript-incorrectly-handles-records-returned-literals</guid>
<pubDate>Fri, 27 Aug 2021 18:53:31 +0000</pubDate>
</item>
<item>
<title>Why does *data-readers* require Vars?</title>
<link>https://ask.clojure.org/index.php/10934/why-does-data-readers-require-vars</link>
<description>&lt;p&gt;&lt;code&gt;edn/read&lt;/code&gt;'s &lt;code&gt;:readers&lt;/code&gt; arg &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojuredocs.org/clojure.edn/read&quot;&gt;accepts&lt;/a&gt; a map of tag symbols to data-reader functions, but &lt;code&gt;*data-readers*&lt;/code&gt; &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojuredocs.org/clojure.core/*data-readers*&quot;&gt;requires&lt;/a&gt; a map of tag symbols to data-reader Vars (global bindings). I'm just wondering if there is any reason for the discrepancy, because it is a bummer not to be able to use anonymous functions in &lt;code&gt;*data-readers*&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The context is I've made a handful of related reader tags (for tagged literals) that all work similarly, so rather than create 5 near identical reader functions I made 1, with two arity (tag, value), then I made a &lt;code&gt;reader-for&lt;/code&gt; function that returns a one-arity function as needed (using &lt;code&gt;partial&lt;/code&gt; and the two-arity function). This works just fine for &lt;code&gt;edn/read&lt;/code&gt; but when I went to use it in &lt;code&gt;*data-readers*&lt;/code&gt; it's a no-go because there is no Var for what comes out of &lt;code&gt;reader-for&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt; There are several workarounds. For example bind &lt;code&gt;*default-data-reader-fn*&lt;/code&gt;and make a function to dispatch to all my readers. Which is not particularly difficult but now I'm left with two artifacts instead of one - the map of readers for &lt;code&gt;edn/read&lt;/code&gt; and the function for &lt;code&gt;*default-data-reader-fn*&lt;/code&gt;. The map can be leveraged in the function of course. Or as an alternative I can just write the five functions -- or &quot;write&quot; them in a &lt;code&gt;doseq&lt;/code&gt;. But the little inconsistencies across how these tags are done is a little baffling. (For example, in addition to the &lt;code&gt;{tag-sym fn}&lt;/code&gt; map of &lt;code&gt;:reader&lt;/code&gt; and the &lt;code&gt;{tag-sym Var}&lt;/code&gt; map of &lt;code&gt;*data-readers*&lt;/code&gt;, there is also the &lt;code&gt;{unquoted-tag-sym-in-a-map-literal fn-sym}&lt;/code&gt; syntax of &lt;code&gt;data_readers.clj&lt;/code&gt;, which despite being a clj file does not seem to afford me the opportunity to do anything dynamic to define readers, just the literal map).&lt;/p&gt;
&lt;p&gt;I probably just don't grasp the practicalities/history/logic behind all this, if anyone can shed some light thanks in advance, if not that's fine too.&lt;/p&gt;
</description>
<category>Syntax and reader</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/10934/why-does-data-readers-require-vars</guid>
<pubDate>Tue, 10 Aug 2021 19:04:31 +0000</pubDate>
</item>
<item>
<title>Are reader tags supposed to support non-ASCII characters?</title>
<link>https://ask.clojure.org/index.php/10481/are-reader-tags-supposed-to-support-non-ascii-characters</link>
<description>&lt;p&gt;I tried defining a Unicode data-literal tag, and was surprised to find that it throws an error:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(defn wrap-λ [expr]
  `(fn [~'%] ~expr))
    
(set! *data-readers*
  (assoc *data-readers*
    'λ #'wrap-λ))

(read-string &quot;#λ(inc %)&quot;)
;; =&amp;gt; Execution error (ArrayIndexOutOfBoundsException) at lib/eval74486 (REPL:15).
;;    Index 955 out of bounds for length 256
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;955 is the Unicode codepoint for \λ, and the error suggests it only supports the ASCII range.&lt;br&gt;
The first few lines of the stacktrace:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;       LispReader.java:  840  clojure.lang.LispReader$DispatchReader/invoke
       LispReader.java:  285  clojure.lang.LispReader/read
       LispReader.java:  216  clojure.lang.LispReader/read
       LispReader.java:  205  clojure.lang.LispReader/read
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Is this expected behavior? Clojurescript does not have the same issue:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(cljs.reader/register-tag-parser! 'λ wrap-λ)
(cljs.reader/read-string &quot;#λ(inc %)&quot;)
;; =&amp;gt; (cljs.core/fn [% &amp;amp; args] (inc %))
&lt;/code&gt;&lt;/pre&gt;
</description>
<category>Syntax and reader</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/10481/are-reader-tags-supposed-to-support-non-ascii-characters</guid>
<pubDate>Thu, 15 Apr 2021 05:48:03 +0000</pubDate>
</item>
<item>
<title>behaviour of data_readers.cljc</title>
<link>https://ask.clojure.org/index.php/9957/behaviour-of-datareaders-cljc</link>
<description>&lt;p&gt;update: I have raised this as an issue: &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojure.atlassian.net/jira/software/c/projects/CLJS/issues/CLJS-3294&quot;&gt;https://clojure.atlassian.net/jira/software/c/projects/CLJS/issues/CLJS-3294&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I am trying to write a library which provides a set of tagged literals (and their reader fns) for consumption from both clojure and clojurescript. &lt;/p&gt;
&lt;p&gt;data_readers.cljc&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;{foo/bar my.project.foo/bar}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;my/project/foo.cljc&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;    (ns my.project.foo)

(defn bar [x]
  #?(:clj (str &quot;hello! &quot; x)
     :cljs (clj-&amp;gt;js x)))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;cmd line: &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;clj --main cljs.main -e &quot;(println #foo/bar \&quot;world\&quot;)&quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;prints &quot;hello, world&quot;&lt;/p&gt;
&lt;p&gt;clojurescript compiles+executes the :clj branch in the bar reader fn - as far as I can see there is no way to execute cljs code in a reader. I have also tried having a &lt;code&gt;my/project/foo.cljs&lt;/code&gt; (ie cljs only) file - but this doesn't work either.&lt;/p&gt;
&lt;p&gt;I have tried using a workaround where the reader function returns a form, see &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/henryw374/time-literals/blob/master/src/time_literals/data_readers.cljc&quot;&gt;https://github.com/henryw374/time-literals/blob/master/src/time_literals/data_readers.cljc&lt;/a&gt; and this works ok, except that now those reader functions don't work when being used with clojure (e.g. clojure.core/read-string) - see &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/henryw374/time-literals/issues/3&quot;&gt;https://github.com/henryw374/time-literals/issues/3&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Thanks,&lt;br&gt;
Henry&lt;/p&gt;
</description>
<category>ClojureScript</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/9957/behaviour-of-datareaders-cljc</guid>
<pubDate>Sun, 20 Dec 2020 08:09:53 +0000</pubDate>
</item>
<item>
<title>Is it possible to create a tagged literal reader for a clojure.core.Vec?</title>
<link>https://ask.clojure.org/index.php/9567/possible-create-tagged-literal-reader-for-clojure-core-vec</link>
<description>&lt;p&gt;Is it not possible to create a tagged literal for a &lt;code&gt;clojure.core.Vec&lt;/code&gt; (that result of the &lt;code&gt;vector-of&lt;/code&gt; function)?  Creating a reader function for such a tag is trivial, and it works well enough with &lt;code&gt;read-str&lt;/code&gt; and EDN readers.  But the REPL always winds up holding a &lt;code&gt;clojure.lang.PersistentVector&lt;/code&gt;.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;This issue came about as I thrash around looking for a round-trip support for a hexstring of bytes with support for idiomatic Clojure (&lt;code&gt;clojure.lang.ISeq&lt;/code&gt; and immutability are high priorities).&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Despite the promise of &lt;code&gt;(vector-of :byte ...)&lt;/code&gt;, it's not possible to    round trip the byte data cleanly with &lt;code&gt;clojure.core.Vec&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;With a tag reader and print-dup writer I can get round-trip ability  for JVM native byte arrays, but they don't support  &lt;code&gt;clojure.lang.ISeq&lt;/code&gt; and they're mutable.&lt;/li&gt;
&lt;li&gt;Regular vectors are heterogeneous and I can't safely appropriate &lt;br&gt;
   &lt;code&gt;print-dup&lt;/code&gt; for them to achieve my goals.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;None of these options are attractive.&lt;/p&gt;
</description>
<category>Syntax and reader</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/9567/possible-create-tagged-literal-reader-for-clojure-core-vec</guid>
<pubDate>Thu, 03 Sep 2020 03:02:38 +0000</pubDate>
</item>
</channel>
</rss>