Open timsgardner opened 5 years ago
On ClojureJVM
user=> (binding [*print-dup* false] (pr-str (into-array Object (list 1 2 3))))
"#object[\"[Ljava.lang.Object;\" 0x42954c45 \"[Ljava.lang.Object;@42954c45\"]"
user=> (binding [*print-dup* true] (pr-str (into-array Object (list 1 2 3))))
IllegalArgumentException No method in multimethod 'print-dup' for dispatch value: class [Ljava.lang.Object; clojure.lang.MultiFn.getFn (MultiFn.java:156)
On the language level, the bug seems to be that (binding [*print-dup* true] (pr-str (into-array Object (list 1 2 3))))
emits anything at all rather than an error. Alternatively, the bug is that ClojureJVM doesn't print arrays readably (and should), and ClojureCLR's version doesn't work (this representation doesn't work with clojure.core/read-string
either).
Whatever the case, we want to be able to serialize arrays. If we're not expressing this as a language patch we have to express it as an intervention on *print-method*
and *data-readers*
. If we do this globally we're effectively patching the language at runtime for our own little project, which isn't great. If we do this locally, we have multiple edn serialization techniques drifting about in the same runtime, which is inherently a bit sketchy.
We're probably going to do the latter (we probably have to anyway). At the very least we should document the dickens out of this because it will lead to great confusion and weird user bugs.
With
*print-dup*
set to false, arrays serialize as lists:With
*print-dup*
set to true, arrays serialize as follows:This doesn't survive
edn/read-string
: