Fork me on GitHub
#vim
<
2022-04-14
>
JohnJ01:04:27

fireplace expands the contents of types on eval, is there flag to avoid this? cider middleware seems to be the culprit

Noah Bogart02:04:06

Contents of types?

JohnJ04:04:21

yes, if you have something like {:foo [email protected]} where bar is some deftype

noisesmith18:04:16

@jjaws do you mean you are getting the str of the item, instead of the pr-str?

(cmd)user=> (str (->Bar))
"[email protected]"
(ins)user=> (pr-str (->Bar))
"#object[user.Bar 0x1d96d872 \"[email protected]\"]"
user=>

dave18:04:40

Neither of those look right to me. In a CLI REPL:

Clojure 1.11.1
user=> (defrecord Bar [])
user.Bar
user=> (pr-str (->Bar))
"#user.Bar{}"

noisesmith18:04:41

that's a record, he said deftype

dave18:04:47

Ah! I missed that part

noisesmith18:04:18

I think the best "your real problem here" answer, is to implement toString on the deftype

dave18:04:44

Also consider using a record instead. In my 10 years of using Clojure, I've used deftype basically never.

noisesmith19:04:24

if you need deftype, this is how to make it print nicely

(cmd)user=> (deftype Bar [] Object (toString [this] "Bar[]"))
user.Bar
(ins)user=> (defmethod print-method Bar [b w] (.write w (str b)))
#object[clojure.lang.MultiFn 0x4b54af3d "[email protected]"]
(cmd)user=> (pr-str (->Bar))
"Bar[]"
(cmd)user=> (str (->Bar))
"Bar[]"
user=>

noisesmith19:04:56

of course, you probably want to print the contents of some fields in the toString, that's an exercise for the reader :D

noisesmith19:04:56

and yeah, defrecord does all this for you automatically, along with some other stuff to make your new class act like a hash map too