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

0 votes
in Clojure by

{{(str 1M)}} produces {{"1"}}
{{(str {:a 1M})}} procuces {{"{:a 1M}"}}

The suffix is lost because {{str}} calls {{.toString}} directly: {{java.lang.BigDecimal}} does not know anything about {{M}} suffix.

.toString on map calls {{RT.print}} and that recursively calls {{RT.print}} for keys and values. {{RT.print}} has a special case for {{java.lang.BigDecimal}}, so it prints the suffix.

6 Answers

0 votes
by
_Comment made by: alexmiller_

If you want to print a string that can later be read, normally you use pr-str. Some reason that’s not better here?

str intentionally does not have the expectation to be readable.
0 votes
by
_Comment made by: dpsutton_

This was discovered originally investigating `spit`. This particular behavior turned out not to be the culprit but was something noticed while investigating.


clojure -e '(spit "foo.edn" 3M)' && cat foo.edn
3

clojure -e '(spit "foo.edn" {:thing 3M})' && cat foo.edn
{:thing 3M}


We were wondering if using spit for edn was a footgun or if it was a genuine bug.
0 votes
by

Comment made by: dottedmag

{{spit}} calls {{str}}, that's how I stumbled upon it.

It's trivial to make a {{pr-spit}} that calls {{pr-str}}, but isn't then {{spit}} kind of useless if its results can't be {{slurp}}ed back?

0 votes
by
_Comment made by: alexmiller_

Oh, well that’s considerably more interesting. As a workaround you could pr-str before you spit.

The question of edn printing is one that has come up several times (there might even be a ticket about it).
0 votes
by

Comment made by: alexmiller

CLJ-1201 is one such ticket

0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJ-2485 (reported by dottedmag)
...