<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Clojure Q&amp;A - Recent questions tagged edn</title>
<link>https://ask.clojure.org/index.php/tag/edn</link>
<description></description>
<item>
<title>Namespaced map conversion fails when namespace keyword starts with a number</title>
<link>https://ask.clojure.org/index.php/15159/namespaced-conversion-fails-namespace-keyword-starts-number</link>
<description>&lt;p&gt;It looks like Clojure has no problem with either :0 or :0/a, but when used together in a namesapced map it fails during some internal conversion.&lt;/p&gt;
&lt;p&gt;Worst part: it prints back an unreadable form when if I feed it {:0/a :val}&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;user=&amp;gt; :0
:0
user=&amp;gt; :0/a
:0/a
user=&amp;gt; {:0/a :val}
#:0{:a :val}
user=&amp;gt; #:0{:a :val}
Syntax error reading source at (REPL:45:5).
Namespaced map must specify a valid namespace: 0
:a
:val
Syntax error reading source at (REPL:45:13).
Unmatched delimiter: }
&lt;/code&gt;&lt;/pre&gt;
</description>
<category>Clojure</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/15159/namespaced-conversion-fails-namespace-keyword-starts-number</guid>
<pubDate>Mon, 06 Jul 2026 15:16:32 +0000</pubDate>
</item>
<item>
<title>[clojure.edn] Leading zeros in numbers</title>
<link>https://ask.clojure.org/index.php/14798/clojure-edn-leading-zeros-in-numbers</link>
<description>&lt;p&gt;clojure.edn allow leading zeros ending up reading such number as octal representation. The problem is that it is also allowed to have indefinite amount of leading zeros for octals:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;000000000000042  ;; =&amp;gt; 34
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and when there is a suffix &quot;M&quot; that forces floating point representation the same string become float 42 stripping all leading zeros.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;000000000000042M ;; =&amp;gt; 42M
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;At the same time EDN specification forbids integers with leading zeros at all even for floats.&lt;br&gt;
I found a ticket about leading zeros in data.json but I think it should be expanded to cover clojure as well.&lt;/p&gt;
&lt;p&gt;In the same scope but origin is in the EDN spec:&lt;br&gt;
float specification allows leading zeroes in exponent and only zeros in fractional parts:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;0.00000000...00
0.0e0001
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;probably because of that clojure.edn read such numbers without error too. &lt;/p&gt;
</description>
<category>Syntax and reader</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14798/clojure-edn-leading-zeros-in-numbers</guid>
<pubDate>Thu, 04 Dec 2025 13:31:23 +0000</pubDate>
</item>
<item>
<title>Docstring clojure.edn/read-string is misleading</title>
<link>https://ask.clojure.org/index.php/14762/docstring-clojure-edn-read-string-is-misleading</link>
<description>&lt;blockquote&gt;&lt;p&gt;  user=&amp;gt; (doc clojure.edn/read-string)&lt;br&gt;
  -------------------------&lt;br&gt;
  clojure.edn/read-string&lt;br&gt;
  ([s] [opts s])&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Reads one object from the string s. Returns nil when s is nil or empty.
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;   Reads data in the edn format (subset of Clojure data):&lt;br&gt;
   &lt;a rel=&quot;nofollow&quot; href=&quot;http://edn-format.org&quot;&gt;http://edn-format.org&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;   opts is a map as per clojure.edn/read&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Note &lt;strong&gt;Returns nil when s is nil or empty.&lt;/strong&gt;. But when called with opts without explicit :eof it throws EOF error&lt;/p&gt;
&lt;p&gt;user=&amp;gt; (clojure.edn/read-string {} &quot;&quot;)&lt;br&gt;
Execution error at user/eval222 (REPL:1).&lt;br&gt;
EOF while reading&lt;/p&gt;
&lt;p&gt;And without options it returns nil as expected&lt;/p&gt;
&lt;p&gt;user=&amp;gt; (clojure.edn/read-string &quot;&quot;)&lt;br&gt;
nil&lt;/p&gt;
</description>
<category>Docs</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14762/docstring-clojure-edn-read-string-is-misleading</guid>
<pubDate>Thu, 20 Nov 2025 15:10:38 +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>clojure.edn parser will not parse complete file in some cases</title>
<link>https://ask.clojure.org/index.php/14537/clojure-edn-parser-will-not-parse-complete-file-in-some-cases</link>
<description>&lt;p&gt;I've noticed that &lt;code&gt;clojure.edn&lt;/code&gt; parser will skip rest of the file if it manages to find the first valid token that will complete collection. For example:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;;; demo.edn
{
 :foo 1
 :bar 2 }
 :baz 3 
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;with:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(require '[clojure.edn :as edn]
         '[clojure.java.io :as io])

(with-open [r (io/reader &quot;demo.edn&quot;)]
  (edn/read (java.io.PushbackReader. r)))

user=&amp;gt; {:foo 1, :bar 2}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It will also ignore rest of the file when the file is clearly malformed:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;{
 :foo 1
 :bar 2 }
xxxx yyyy }}}}} {{{{ ((
 :baz 3 
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;it returns again:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;user=&amp;gt; {:foo 1, :bar 2}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I was expecting it to throw EOF exception or at least '}' mismatch. Is this behavior by design or a possible bug?&lt;/p&gt;
</description>
<category>Syntax and reader</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14537/clojure-edn-parser-will-not-parse-complete-file-in-some-cases</guid>
<pubDate>Wed, 07 May 2025 12:29:34 +0000</pubDate>
</item>
<item>
<title>How to persist Clojure data structures to disk?</title>
<link>https://ask.clojure.org/index.php/14203/how-to-persist-clojure-data-structures-to-disk</link>
<description>&lt;p&gt;Hello,&lt;br&gt;
I'm building a web crawler in Clojure that records its results in a map of maps. The data structure basically looks like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;{&quot;https://example.org&quot; {:base-url &quot;https://example.org&quot;
                        :crawled {&quot;/blog&quot; {:relevant true :status 200}
                                  &quot;/contact&quot; {:relevant false :status 200}}
 &quot;https://foo.com&quot; {:base-url &quot;https://foo.com&quot;
                    :crawled {&quot;/home&quot; {:relevant true :status 200}}}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The web crawler is feed with a list of websites. However, for the sake of efficiency I want to avoid crawling already crawled websites. Therefore, I was looking for a way to persist the above data structure so that it can be consulted in subsequent runs to check if a given website was already crawled. (Of course, I have other reasons to store the results too, e.g. to do various analysis on the captured data)&lt;/p&gt;
&lt;p&gt;First, I thought &lt;strong&gt;EDN&lt;/strong&gt; would be a perfect solution. To my surprise, &lt;code&gt;clojure.edn&lt;/code&gt; does not have &lt;code&gt;write&lt;/code&gt; functions. A lot of advice online says to use &lt;code&gt;pr-str&lt;/code&gt;. However, using &lt;code&gt;pr-str&lt;/code&gt; has caveats as pointed out in &lt;a rel=&quot;nofollow&quot; href=&quot;https://nitor.com/en/articles/pitfalls-and-bumps-clojures-extensible-data-notation-edn&quot;&gt;https://nitor.com/en/articles/pitfalls-and-bumps-clojures-extensible-data-notation-edn&lt;/a&gt; (e.g. possbile truncations when &lt;em&gt;print-length&lt;/em&gt; is set). And it's totally possible to generate invalid edn as pointed out in this comment by @alexmiller: &lt;a rel=&quot;nofollow&quot; href=&quot;https://ask.clojure.org/index.php/10278/should-pr-str-on-a-function-produce-valid-edn-syntax?show=10282#c10282&quot;&gt;https://ask.clojure.org/index.php/10278/should-pr-str-on-a-function-produce-valid-edn-syntax?show=10282#c10282&lt;/a&gt;. &lt;/p&gt;
&lt;p&gt;Despite &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojuredocs.org/clojure.edn&quot;&gt;https://clojuredocs.org/clojure.edn&lt;/a&gt; claiming that it is &quot;designed to be used in a similar way to JSON or XML&quot; I have the impression it is more geared towards writing edn files by hand (i.e. configuration files).&lt;/p&gt;
&lt;p&gt;Looking for alternatives, I stumbled upon Transit. However, its mainly intended &quot;as a wire protocol for transferring data between applications&quot;. And the README further says&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;If storing Transit data durably, readers and writers are expected to use the same version of Transit and you are responsible for migrating/transforming/re-storing that data when and if the transit format changes.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Because in Clojure, data is code and code is data and because of the existence of EDN, I really thought persisting simple data structures like the above would be a breeze in Clojure. &lt;/p&gt;
&lt;p&gt;Instead I see these sub-optimal options with my current knowledge:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Hope that &lt;code&gt;pr-str&lt;/code&gt; produces valid EDN without loss in my particular case&lt;/li&gt;
&lt;li&gt;Build a custom XML serialization&lt;/li&gt;
&lt;li&gt;Use Transit&lt;/li&gt;
&lt;li&gt;Use JSON?! (what about keywords etc.?!)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Is there a more idiomatic way to store and read back in simple Clojure data structures?&lt;/p&gt;
</description>
<category>Collections</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14203/how-to-persist-clojure-data-structures-to-disk</guid>
<pubDate>Tue, 22 Oct 2024 08:45:52 +0000</pubDate>
</item>
<item>
<title>Is edn-format.org supposed to be online?</title>
<link>https://ask.clojure.org/index.php/14116/is-edn-format-org-supposed-to-be-online</link>
<description>&lt;p&gt;The documentation of &lt;code&gt;clojure.edn/read&lt;/code&gt; references &lt;a rel=&quot;nofollow&quot; href=&quot;http://edn-format.org&quot;&gt;http://edn-format.org&lt;/a&gt;. However, it is offline.&lt;/p&gt;
&lt;p&gt;A Whois query results in name servers like ns1170.dns.dyn.com. When doing the dig query &lt;code&gt;dig @dns.google.com edn-format.org NS&lt;/code&gt;, I got &quot;Network Error&quot; messages.&lt;/p&gt;
&lt;p&gt;Maybe &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/edn-format/edn&quot;&gt;https://github.com/edn-format/edn&lt;/a&gt; is supposed to replace edn-format.org. In this case, updating the api reference would be good.&lt;/p&gt;
&lt;p&gt;In addition, &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojuredocs.org/clojure.edn&quot;&gt;https://clojuredocs.org/clojure.edn&lt;/a&gt; references edn-format.org as well.&lt;/p&gt;
</description>
<category>Docs</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14116/is-edn-format-org-supposed-to-be-online</guid>
<pubDate>Wed, 18 Sep 2024 09:29:07 +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>How to store Hiccup HTML structures in EDN files?</title>
<link>https://ask.clojure.org/index.php/12485/how-to-store-hiccup-html-structures-in-edn-files</link>
<description>&lt;p&gt;I want to store blog posts in EDN file like the one shown below and then convert them to HTML.&lt;/p&gt;
&lt;p&gt;Here is a sample file:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;    {:slug &quot;slug&quot;
 :title &quot;The first blog post&quot;
 :body [[:div
         [:p &quot;First paragraph&quot;]
         [:ul

          [:li &quot;List Item 1&quot;]
          [:li &quot;List Item 2&quot;]
          [:li &quot;List Item 3&quot;]]

         [:p &quot;Second paragraph&quot;]]]}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then I try to read it using the following code:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(ns cl-www.core
  (:use [hiccup.core])
  (:require [cl-www.logic :refer [render-everything]]
            [cl-www.common :refer [prettify-html]]
            [clojure.edn]
            [clojure.java.io])
  (:import (org.jsoup Jsoup)
           (org.jsoup.nodes Document))
  (:gen-class))

(def path &quot;/Users/myuser/cl-www/resources/p-2022-12-17.edn&quot;)

(defn test-edn
  []
  (let [post-data (-&amp;gt; path
                      (slurp)
                      (read-string))
        post-struct (:body post-data)
        html-struct [:html
                     [:body
                      [:h1 &quot;Hello&quot;]
                      post-struct]]

        html (-&amp;gt;&amp;gt; html-struct
                  (html)
                  (prettify-html))]

    (println html)))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;When I run &lt;code&gt;(test-edn)&lt;/code&gt; I get the following error:&lt;br&gt;
&lt;code&gt;Execution error (IllegalArgumentException) at hiccup.compiler/normalize-element (compiler.clj:59).
[:div [:p &quot;First paragraph&quot;] [:ul [:li &quot;List Item 1&quot;] [:li &quot;List Item 2&quot;] [:li &quot;List Item 3&quot;]] [:p &quot;Second paragraph&quot;]] is not a valid element name.&lt;/code&gt;&lt;br&gt;
How can I fix it, i. e. &lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;manually write a EDN file, then &lt;/li&gt;
&lt;li&gt;read it in Clojure, &lt;/li&gt;
&lt;li&gt;insert into a Hiccup structure, and &lt;/li&gt;
&lt;li&gt;export it to HTML?&lt;/li&gt;
&lt;/ol&gt;
</description>
<category>Clojure</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/12485/how-to-store-hiccup-html-structures-in-edn-files</guid>
<pubDate>Sat, 17 Dec 2022 18:50:52 +0000</pubDate>
</item>
<item>
<title>Programmatically connect dependencies to the maven repos that provide them</title>
<link>https://ask.clojure.org/index.php/12383/programmatically-connect-dependencies-maven-repos-provide</link>
<description>&lt;p&gt;As a Clojure developer,&lt;br&gt;
I want to be able to link project dependencies to the maven repos that provide them&lt;br&gt;
so that a) tools that work with dependencies (e.g. &lt;code&gt;nvd-clojure&lt;/code&gt;, &lt;code&gt;clj-watson&lt;/code&gt;) have more first-hand information to work with, b) I can easily find out custom maven repos that are no longer used and c) get a better understanding in general of what my project is composed of.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Workaround&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;clj -Sdeps '{:mvn/local-repo &quot;tmp&quot;}' -Stree&lt;/code&gt; uses a custom local maven repo to force a redownload of the jars and provides a way to do the above by looking at the messages (e.g. &lt;code&gt;Downloading: org/clojure/clojure/1.11.1/clojure-1.11.1.pom from central&lt;/code&gt;), so it can be ok in some cases.&lt;/p&gt;
&lt;p&gt;Would you consider simplifying this process by providing a way to get that information as data? I would love to have it in &lt;code&gt;clj -X:deps tree :format :edn&lt;/code&gt; for instance.&lt;/p&gt;
</description>
<category>Clojure CLI</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/12383/programmatically-connect-dependencies-maven-repos-provide</guid>
<pubDate>Fri, 11 Nov 2022 20:38:29 +0000</pubDate>
</item>
<item>
<title>Adding support for byte sequences to the EDN standard</title>
<link>https://ask.clojure.org/index.php/11019/adding-support-for-byte-sequences-to-the-edn-standard</link>
<description>&lt;p&gt;How do I get support for byte sequences to EDN?  One implementation might be from adopting the mechanism used by Bencode: &lt;a rel=&quot;nofollow&quot; href=&quot;https://wiki.theory.org/index.php/BitTorrentSpecification#Bencoding&quot;&gt;https://wiki.theory.org/index.php/BitTorrentSpecification#Bencoding&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;This still requires some context and doesn't allow for top level direct arbitrary binary to be accepted as valid.  I'm not sure this is the best method, but I do need some way to represent arbitrary binary blobs well.   One thing to also consider is interrupted data, which bencode's approach does not work well with.  That might always be an application level concern, I'm not sure.&lt;/p&gt;
</description>
<category>Contrib libs</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/11019/adding-support-for-byte-sequences-to-the-edn-standard</guid>
<pubDate>Tue, 07 Sep 2021 23:30:50 +0000</pubDate>
</item>
<item>
<title>How do I effectively use EDN with C/C++?</title>
<link>https://ask.clojure.org/index.php/11014/how-do-i-effectively-use-edn-with-c-c</link>
<description>&lt;p&gt;Hello, I'm very new to Clojure related technologies and I may be asking the wrong question.&lt;/p&gt;
&lt;p&gt;I am looking into making a IPFS like proof of concept using EDN which can be integrated with classical system languages (namely the old duo of C/C++).  I would like to create an interface for C++ that takes a template data structure from compile time and from a filename create and populate a data structure matching that template.  In C, it would be some ugly thing with structs composed of an enum to indicate the current primitive (either a list, set, or bytes), a void pointer, and all that C hackiness. Then from these, similarly have serializes.&lt;/p&gt;
&lt;p&gt;The reason for EDN in particular is that it appears to be a technically superior specification based on it's foundations.  The lack of need for a top level containing data structure, and extensible types look like a very good foundation for any work.  It looks like EDN is missing the same level of support as formats like JSON.  That makes this tough, but I think I can justify contributing something here.  I am looking for a solution that can be reused at some point as a part of a Linux kernel module for embedding this functionality as a file system, but that's a ways off.&lt;/p&gt;
&lt;p&gt;How do I start on this kind of project?  What details am I missing?&lt;/p&gt;
</description>
<category>Contrib libs</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/11014/how-do-i-effectively-use-edn-with-c-c</guid>
<pubDate>Tue, 07 Sep 2021 01:55:21 +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>No metadata on clojure 1.9 map literals</title>
<link>https://ask.clojure.org/index.php/10724/no-metadata-on-clojure-1-9-map-literals</link>
<description>&lt;p&gt;Maps written using the new &lt;code&gt;#:default.namespace{,,,}&lt;/code&gt; syntax don't get file positions attached as metadata.&lt;/p&gt;
&lt;p&gt;Given this setup code&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(require '[clojure.tools.reader :as reader])
(require '[clojure.tools.reader.reader-types :as reader-types])

(defn sample [s]
  (with-open [r (java.io.StringReader. s)]
    (meta (reader/read (reader-types/indexing-push-back-reader (reader-types/push-back-reader r) 1)))))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;this edn literal fails to get parsed with positional metadata&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(sample &quot;#:ns{ :key :val }&quot;) ; =&amp;gt; nil
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;unlike those two, which get their positional metadata as expected&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(sample &quot;{ :key :val }&quot;)     ; =&amp;gt; {:line 1, :column 1, :end-line 1, :end-column 14}
(sample &quot;{ :ns/key val }&quot;)   ; =&amp;gt; {:line 1, :column 1, :end-line 1, :end-column 16}
&lt;/code&gt;&lt;/pre&gt;
</description>
<category>tools.reader</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/10724/no-metadata-on-clojure-1-9-map-literals</guid>
<pubDate>Wed, 23 Jun 2021 07:40:15 +0000</pubDate>
</item>
<item>
<title>Looking for a safe way to read EDN with file position metadata</title>
<link>https://ask.clojure.org/index.php/10722/looking-for-safe-way-to-read-edn-with-file-position-metadata</link>
<description>&lt;p&gt;I'm parsing untrusted data. To improve error reporting, I'd like to  keep track of file positions.&lt;/p&gt;
&lt;p&gt;As far as I can tell, &lt;code&gt;clojure.tools.reader.edn/read&lt;/code&gt; is the correct tool for untrusted data, but it doesn't do file position metadata, whereas &lt;code&gt;clojure.tools.reader/read&lt;/code&gt; has the file position metadata, but it can end up running code on behalf of the untrusted data, which is obviously not ideal.&lt;/p&gt;
&lt;p&gt;If I bind &lt;em&gt;data-readers&lt;/em&gt; to a map of know-safe readers, and &lt;em&gt;read-eval&lt;/em&gt; to false, would that still leave me open to unwanted code execution by the untrusted data, or would it make &lt;code&gt;clojure.tools.reader/read&lt;/code&gt; safe to use on my EDN?&lt;/p&gt;
</description>
<category>tools.reader</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/10722/looking-for-safe-way-to-read-edn-with-file-position-metadata</guid>
<pubDate>Wed, 23 Jun 2021 07:32:57 +0000</pubDate>
</item>
<item>
<title>What's up with this difference between reading UUIDs in edn between clj and cljs?</title>
<link>https://ask.clojure.org/index.php/10524/whats-with-this-difference-between-reading-uuids-between-cljs</link>
<description>&lt;p&gt;Hello! As ever, super-grateful for cljs - it's a huge multiplier on our efforts and we continue to love it as we use it all day long every day.&lt;/p&gt;
&lt;p&gt;After upgrading clojurescript versions,  we started getting a strange &lt;code&gt;read-string&lt;/code&gt; related error: &quot;No reader function for tag uuid.&quot;&lt;/p&gt;
&lt;h2&gt;cljs repl:&lt;/h2&gt;
&lt;pre&gt;&lt;code&gt;ClojureScript 1.10.238
app:cljs.user=&amp;gt; (cljs.tools.reader.edn/read-string &quot;#uuid \&quot;eed86fd1-4110-44d8-8f41-27473029cc6a\&quot;&quot;)
#error {:message &quot;No reader function for tag uuid.&quot;, :data {:type :reader-exception, :ex-kind :reader-error}}
   new (jar:file:/home/harold/.m2/repository/org/clojure/clojurescript/1.10.238/clojurescript-1.10.238.jar!/cljs/core.cljs:11123:11)
   Function.cljs$core$IFn$_invoke$arity$3 (jar:file:/home/harold/.m2/repository/org/clojure/clojurescript/1.10.238/clojurescript-1.10.238.jar!/cljs/core.cljs:11155:5)
   Function.cljs$core$IFn$_invoke$arity$2 (jar:file:/home/harold/.m2/repository/org/clojure/clojurescript/1.10.238/clojurescript-1.10.238.jar!/cljs/core.cljs:11153:16)
   cljs.core/ex-info (jar:file:/home/harold/.m2/repository/org/clojure/clojurescript/1.10.238/clojurescript-1.10.238.jar!/cljs/core.cljs:11150:1)
   Function.cljs$core$IFn$_invoke$arity$variadic (jar:file:/home/harold/.m2/repository/org/clojure/tools.reader/1.3.3/tools.reader-1.3.3.jar!/cljs/tools/reader/impl/errors.cljs:37:13)
   cljs.tools.reader.impl.errors/throw-ex (jar:file:/home/harold/.m2/repository/org/clojure/tools.reader/1.3.3/tools.reader-1.3.3.jar!/cljs/tools/reader/impl/errors.cljs:26:1)
   Function.cljs$core$IFn$_invoke$arity$variadic (jar:file:/home/harold/.m2/repository/org/clojure/tools.reader/1.3.3/tools.reader-1.3.3.jar!/cljs/tools/reader/impl/errors.cljs:43:4)
   cljs.tools.reader.impl.errors/reader-error (jar:file:/home/harold/.m2/repository/org/clojure/tools.reader/1.3.3/tools.reader-1.3.3.jar!/cljs/tools/reader/impl/errors.cljs:39:1)
   cljs.tools.reader.impl.errors/throw-unknown-reader-tag (jar:file:/home/harold/.m2/repository/org/clojure/tools.reader/1.3.3/tools.reader-1.3.3.jar!/cljs/tools/reader/impl/errors.cljs:221:4)
   cljs$tools$reader$edn$read_tagged (jar:file:/home/harold/.m2/repository/org/clojure/tools.reader/1.3.3/tools.reader-1.3.3.jar!/cljs/tools/reader/edn.cljs:372:10)

app:cljs.user=&amp;gt; (cljs.tools.reader.edn/read-string {:readers {'uuid uuid}} &quot;#uuid \&quot;eed86fd1-4110-44d8-8f41-27473029cc6a\&quot;&quot;)
#uuid &quot;eed86fd1-4110-44d8-8f41-27473029cc6a&quot;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;clj repl:&lt;/h2&gt;
&lt;pre&gt;&lt;code&gt;&amp;gt; (clojure.edn/read-string &quot;#uuid \&quot;eed86fd1-4110-44d8-8f41-27473029cc6a\&quot;&quot;)
#uuid &quot;eed86fd1-4110-44d8-8f41-27473029cc6a&quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;hr&gt;
&lt;p&gt;Previously, reading edn behaved more similarly between cljs and clj. I found the workaround of passing the map as the first argument by looking at the tests in tools.reader.&lt;/p&gt;
&lt;p&gt;Is this expected?&lt;/p&gt;
&lt;p&gt;Thanks for your time and consideration.&lt;/p&gt;
</description>
<category>ClojureScript</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/10524/whats-with-this-difference-between-reading-uuids-between-cljs</guid>
<pubDate>Mon, 26 Apr 2021 16:43:57 +0000</pubDate>
</item>
<item>
<title>Should pr-str on a function produce valid edn syntax?</title>
<link>https://ask.clojure.org/index.php/10278/should-pr-str-on-a-function-produce-valid-edn-syntax</link>
<description>&lt;p&gt;Is the &lt;code&gt;print-method&lt;/code&gt; implementation for functions intended to produce valid &lt;code&gt;edn&lt;/code&gt; syntax? In some cases, it does not:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;user&amp;gt; (require '[org.httpkit.server :as http])
user&amp;gt; (def s (http/run-server (fn [req] {:status 200}) {}))
user&amp;gt; (prn s)
#function[clojure.lang.AFunction/1]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Symbol names can't start with a number, so &lt;code&gt;clojure.lang.AFunction/1&lt;/code&gt; causes a parse error when read back:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;user&amp;gt; (clojure.edn/read-string (prn-str s))
Execution error at user/eval7394 (REPL:68).
Invalid token: clojure.lang.AFunction/1
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Is this the expected behavior? If so, printing and re-reading data structures that may contain fns can fail.&lt;/p&gt;
</description>
<category>Printing</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/10278/should-pr-str-on-a-function-produce-valid-edn-syntax</guid>
<pubDate>Wed, 03 Mar 2021 03:28:04 +0000</pubDate>
</item>
<item>
<title>Exhaustive spec checking like spec/keys, how?</title>
<link>https://ask.clojure.org/index.php/9329/exhaustive-spec-checking-like-spec-keys-how</link>
<description>&lt;p&gt;My understanding is that spec/keys works for validating specific keys in a hash-map. However, I need it to also reject a hash-map that contains keys that are not in :req and :opt.&lt;/p&gt;
&lt;p&gt;For a contrived example, imagine I have a definition of a person as an edn:&lt;/p&gt;
&lt;p&gt;{:name &quot;John&quot;&lt;br&gt;
 :age 25}&lt;/p&gt;
&lt;p&gt;The spec could be:&lt;/p&gt;
&lt;p&gt;(spec/def ::name string?)&lt;br&gt;
(spec/def ::age int?)&lt;br&gt;
(spec/def ::person (spec/keys :req-un [::name ::age]))&lt;/p&gt;
&lt;p&gt;The above definition would conform to this ::person spec.&lt;/p&gt;
&lt;p&gt;However, let's say that, due to a confusion by a developer, another key unrelated to a Person's definition was added, and the hash-map is now:&lt;/p&gt;
&lt;p&gt;{:name &quot;John&quot;&lt;br&gt;
 :age 25&lt;br&gt;
 :voltage 220}&lt;/p&gt;
&lt;p&gt;That would still conform to the spec. But I want it to fail!&lt;/p&gt;
&lt;p&gt;Is there a simple way to make spec/keys reject a hash-map that has keys that are neither req nor opt?&lt;/p&gt;
</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/9329/exhaustive-spec-checking-like-spec-keys-how</guid>
<pubDate>Tue, 26 May 2020 17:59:15 +0000</pubDate>
</item>
<item>
<title>Programatically modifying an edn file that uses data reader functions</title>
<link>https://ask.clojure.org/index.php/9275/programatically-modifying-file-that-uses-reader-functions</link>
<description>&lt;p&gt;Say I have an edn file like this:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;{:name :some-name&lt;br&gt;
 :some-key #my/data-reader-fn [1 2 3]}&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Now say I want to change the content of &lt;code&gt;:name&lt;/code&gt; programatically.&lt;/p&gt;
&lt;p&gt;If I read the edn file, the data-reader-fn will be applied, and so if I want to write my changes to the edn file, &lt;code&gt;:some-key&lt;/code&gt; will be changed too.&lt;/p&gt;
&lt;p&gt;Is there a workaround for this problem? &lt;/p&gt;
</description>
<category>Syntax and reader</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/9275/programatically-modifying-file-that-uses-reader-functions</guid>
<pubDate>Wed, 29 Apr 2020 15:49:47 +0000</pubDate>
</item>
<item>
<title>is there a version of pr-str that emit full versions of qualified keywords in maps instead of short forms?</title>
<link>https://ask.clojure.org/index.php/9222/there-version-versions-qualified-keywords-instead-short-forms</link>
<description>&lt;p&gt; Something like &lt;code&gt;{:foo/bar 1}&lt;/code&gt; instead of &lt;code&gt;#:foo{:bar 1}&lt;/code&gt;&lt;br&gt;
I need to debug some edn and it's impossible to jump to the desired keywords if they're in the short forms.&lt;/p&gt;
</description>
<category>Syntax and reader</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/9222/there-version-versions-qualified-keywords-instead-short-forms</guid>
<pubDate>Fri, 10 Apr 2020 07:54:25 +0000</pubDate>
</item>
</channel>
</rss>