Fork me on GitHub

Is this a known clojure.edn/read-string bug?

(edn/read-string "2something") => throws exception: Invalid number: 2something
(edn/read-string "something2") => works


nvm, edn says it should not start with number

👍 2

Just to remind you of the obvious, which you already know, but are probably forgetting during the context switch between a string and the edn inside that string: something2 would be a symbol, right? And symbols cannot start with numbers, so 2something is not a valid symbol. But it also is obviously not a valid number. So what should it be read as that would be valid?


Yeah, indeed, the issue was a string in my code actually that later becomes a symbol and things blow up :)

Alex Sky20:04:54

(edn/read-string "\"2something\"")


When I print some objects with custom tagged literals, the tag is preserved.

(println ( 240.298 298.29 30 30))
;; =>{:p [240.298 298.29], :size [30.0 30.0]}
but when I use clojure.pprint/pprint to print them, it is not.
(clojure.pprint/pprint ( 240.298 298.29 30 30))
;; => {:p [240.298 298.29], :size [30.0 30.0]}
is there a version of pprint that will preserve custom tagged literals the way print and pr-str will?


It seems like it should be possible to achieve what I'm trying to do - which is pretty print a custom record while also inserting line breaks by binding clojure.pprint/*print-right-margin* - using clojure.pprint/*print-pprint-dispatch*. But I'm not quite sure how.


Print uses a different system of extension


The dispatch stuff in the docs


I've never defined my own, it just ships with different dispatchers (or whatever they are called) for formatting how code is printed vs data


If I'm understanding you correctly, the thing to do might be to define my own dispatch for the custom Record, following this example, correct?


Yeah, as a start, but the body of the example there is pretty poor (just calling pr)


yeah, that implementation won't respect the rebound value of *print-right-margin* - it just puts everything on one line.


Doing that will stop any pprint specific options applying to how the intervals of the record are printed


What you need to do is decompose your record into parts (a tag and a map or whatever) and then as pprint to print those parts


yeah, I'd have to start with something like this extremely oversimplified example, I think:

(let [r ( 240.298 298.29 30 30)
        lit (tagged-literal ' (into {} r))]
    (str "#" (:tag lit) " " (:form lit)))