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

0 votes
in Printing by
{{pr}} misrepresents a structmap containing namespaced-keyword keys.  {{pr}} misstates actual keys' values, and includes phantom keys.


user=> (pr-str (struct (create-struct :q/a :q/b :q/c) 1 2 3))
"#:q{:q/a nil, :q/b nil, :q/c nil, :c 3, :b 2, :a 1}"



It worked in Clojure 1.8, and disabling the print-namespace-maps feature appears to work around the problem:


user=> (binding [*print-namespace-maps* false]
         (pr-str (struct (create-struct :q/a :q/b :q/c) 1 2 3)))
"{:q/a 1, :q/b 2, :q/c 3}"



By the way: Structmaps are (now as ever) appropriate when the basis is anonymous and computed (not coded) or key order is a significant aspect of the basis.  People sometimes cite the reference doc's statement, "Most uses of StructMaps would now be better served by records", but, of course, it is referring only to those uses that are _actually_ better served by records.  Record classes can't be anonymous and defrecord needs the basis at compile time; and normal maps do not exhibit a preset key order.  Thus the continuing relevance of structmaps.

1 Answer

0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJ-2469 (reported by alex+import)
...