Why not just have #keyword and #symbol reader syntax tags that pr could produce for situations like this? It's really preferable that pr not throw exceptions, but it's also quite an abomination that it silently produces bad edn.
On Wednesday, August 3, 2016, Blake Miller <blak3mil...@gmail.com> wrote: > Thanks for that concise explanation, Sean. It makes sense to me that not > all valid Clojure data is serializable. > > There's still something about this that doesn't quite make sense to me, > though: > > clojure.core/pr, rather than throwing an exception when asked to serialize > an instance of clojure.core.Keyword that cannot be serialized, it simply > produces bad output. Bad = will cause the reader to throw. > > Wouldn't it be preferable for pr to throw in this case? > > The way I found out about this was the not-very-informative exception "Map > literal must contain an even number of forms", because pr was fine with > making a string that the reader wouldn't accept. > > Can anyone think of a good reason why pr should *not* throw an exception on > > (pr (keyword "foo bar")) > > since there's no way of expressing that keyword as valid EDN? > > > > On Thursday, August 4, 2016 at 12:16:47 AM UTC, Sean Corfield wrote: >> >> You can programmatically create keywords that are illegal as literals, >> i.e., will not be accepted by the reader. >> >> >> >> This is not a fault of clojure.core/pr – if it is given a value that uses >> legal (readable) keywords, its result will indeed be readable by >> clojure.core/read-string. >> >> >> >> You can also programmatically create symbols that are illegal as far as >> the reader is concerned. >> >> >> >> Sean Corfield -- (970) FOR-SEAN -- (904) 302-SEAN >> An Architect's View -- http://corfield.org/ >> >> "If you're not annoying somebody, you're not really alive." >> -- Margaret Atwood >> >> >> >> On 8/3/16, 4:37 PM, "Blake Miller" <clo...@googlegroups.com on behalf of >> blak3...@gmail.com> wrote: >> >> >> >> I have tried this with Clojure 1.7.0, 1.8.0 and 1.9.0-alpha10 >> >> (clojure.core/read-string (clojure.core/with-out-str (clojure.core/pr >> (clojure.core/keyword "A valid keyword")))) ;; => :A >> >> >> This just seems wrong. It's valid to have an instance of >> clojure.lang.Keyword with a space in its name. >> >> (clojure.core/with-out-str (clojure.core/pr (clojure.core/keyword "A >> valid keyword"))) => ":A valid keyword" >> >> >> >> So, it seems like clojure.core/pr and clojure.core/read-string disagree >> about EDN. >> >> >> >> Is EDN formally specified? https://github.com/edn-format/edn/issues/56 >> seems to suggest it is not. >> >> I ran into this problem using ptaoussanis/sente to pass EDN over a >> websocket. The EDN contained a keyword with a space in it, and the >> clojure(jvm) part of sente had no problem serializing it, but the >> ClojureScript part of sente barfed on it. I thought it was a bug in sente, >> however sente simply calls clojure.core/pr to do the serialization... so I >> played with pr vs read-string and found that they disagree. >> >> >> >> The serialization that clojure.core/pr does on a keyword with a space in >> it seems broken to me: >> >> >> >> user> (clojure.core/with-out-str (clojure.core/pr {:onekey 1 >> >> (clojure.core/keyword >> "two key") 2})) >> >> "{:onekey 1, :two key 2}" >> >> There doesn't seem to be any way to parse that unambiguously. >> >> I think this is a bug. What do you think? >> >> >> https://github.com/ptaoussanis/sente/issues/251 >> >> >> >> >> >> -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > <javascript:_e(%7B%7D,'cvml','clojure@googlegroups.com');> > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > <javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@googlegroups.com');> > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > --- > You received this message because you are subscribed to the Google Groups > "Clojure" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to clojure+unsubscr...@googlegroups.com > <javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@googlegroups.com');>. > For more options, visit https://groups.google.com/d/optout. > -- -- Dan Burton -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.