This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-04-14
Channels
- # aleph (2)
- # announcements (11)
- # aws (4)
- # babashka (42)
- # babashka-sci-dev (81)
- # beginners (90)
- # biff (2)
- # calva (40)
- # cider (16)
- # clj-kondo (26)
- # clj-on-windows (1)
- # cljdoc (4)
- # cljfx (1)
- # cljsrn (2)
- # clojure (92)
- # clojure-austin (2)
- # clojure-europe (23)
- # clojure-nl (5)
- # clojure-uk (3)
- # clojured (3)
- # clojurescript (19)
- # community-development (3)
- # conjure (1)
- # cursive (4)
- # datalevin (3)
- # datomic (5)
- # emacs (13)
- # events (1)
- # fulcro (26)
- # graphql (1)
- # hugsql (15)
- # introduce-yourself (5)
- # leiningen (1)
- # lsp (29)
- # minecraft (19)
- # music (1)
- # off-topic (36)
- # pathom (12)
- # podcasts-discuss (2)
- # portal (8)
- # re-frame (12)
- # reagent (11)
- # rewrite-clj (4)
- # shadow-cljs (56)
- # spacemacs (2)
- # vim (12)
- # windows (3)
- # xtdb (43)
fireplace expands the contents of types on eval, is there flag to avoid this? cider middleware seems to be the culprit
Contents of types?
@jjaws do you mean you are getting the str
of the item, instead of the pr-str
?
(cmd)user=> (str (->Bar))
"user.Bar@528f8f8b"
(ins)user=> (pr-str (->Bar))
"#object[user.Bar 0x1d96d872 \"user.Bar@1d96d872\"]"
user=>
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{}"
that's a record, he said deftype
I think the best "your real problem here" answer, is to implement toString on the deftype
Also consider using a record instead. In my 10 years of using Clojure, I've used deftype basically never.
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 "clojure.lang.MultiFn@4b54af3d"]
(cmd)user=> (pr-str (->Bar))
"Bar[]"
(cmd)user=> (str (->Bar))
"Bar[]"
user=>
of course, you probably want to print the contents of some fields in the toString, that's an exercise for the reader :D
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