conjure icon indicating copy to clipboard operation
conjure copied to clipboard

Printing Records as regular maps

Open esciafardini opened this issue 2 years ago • 2 comments

As requested by Olical on Clojurians slack - posting here:

in emacs a record would print with some metadata:
=> #my_records.Person{:age 55, :weight 165, :height 6.1}

With conjure it’s just a map:
 =>{:age 55, :weight 165, :height 6.1}

From Olical: I'd imagine this is the pretty printer configured in nREPL that's printing it like this. Maybe it can be configured differently to print the prefix too.

esciafardini avatar May 20 '22 14:05 esciafardini

For clarity, it would be better if the REPL printout made a distinction between Records & Hash-Maps (this is probably obvious, but I feel the need to be explicit about the issue)

esciafardini avatar May 20 '22 14:05 esciafardini

Ah! This is a Clojure bug of sorts! https://clojure.atlassian.net/browse/CLJ-1890

I use pprint under the hood to format your responses. I guess CIDER in Emacs is using pr which won't format nicely but does preserve the record type prefix. I'm not sure how to get around this... maybe include my own patched pprint and send it to the REPL as I connect? Seems kinda gross.

Or I rely on other printing tools if they're available in the REPL. For now, the best solution is to :let g:conjure#client#clojure#nrepl#eval#pretty_print = v:false, which obviously disables pretty printing but will (I think) print maps in the exact same way CIDER does since it'll rely on the same function (pr, I think).

So we may not be able to do this really. Unless there's a built in pretty printer function inside Clojure (or maybe the CIDER middleware?) that prints records like this? I could maybe write something to say "if the user has [some awesome pretty printer dep] installed then use that instead" but that's a little fiddly and maybe not worth it.

Olical avatar May 28 '22 11:05 Olical