This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-04-15
Channels
- # announcements (10)
- # beginners (113)
- # calva (2)
- # cider (75)
- # clj-kondo (1)
- # cljdoc (2)
- # clojure (142)
- # clojure-europe (11)
- # clojure-gamedev (6)
- # clojure-italy (7)
- # clojure-nl (8)
- # clojure-spec (3)
- # clojure-uk (50)
- # clojurescript (47)
- # cursive (7)
- # data-science (22)
- # datomic (12)
- # dirac (3)
- # events (1)
- # fulcro (114)
- # gorilla (1)
- # jackdaw (5)
- # joker (3)
- # kaocha (10)
- # leiningen (1)
- # liberator (2)
- # mount (6)
- # nrepl (1)
- # off-topic (16)
- # pathom (34)
- # pedestal (3)
- # re-frame (19)
- # reagent (11)
- # remote-jobs (5)
- # shadow-cljs (127)
- # spacemacs (12)
- # test-check (15)
- # tools-deps (8)
- # vim (4)
Recently learned that prn-str
and edn/read-string
are not symmetric, thanks to playing around with test.check.
(defspec prop-symmetric
;; NOTE This actually fails. prn-str and read-string are not symmetric.
100
(prop/for-all [s gen/any]
(let [encoded (prn-str s)]
(and (string? encoded)
(= s (edn/read-string encoded))))))
(Note, there isn’t any official documentation that they are supposed to be, if you exclude the comment here https://clojuredocs.org/clojure.edn/read-string#example-542dc112e4b05f4d257a2993 from phreed)
the first thing I can think of is things like (keyword " ")
I can't remember if gen/any
tries to generate those though; I think it doesn't
I'm 99.7% sure it doesn't after thinking about it for two more seconds
(symbol "true")
would be problematic; I don't think it avoids that, but it's also probably highly unlikely to generate it by chance
I know that a Double/NAN
is one thing that isn’t symmetric.
I'm sure there's something much more basic
oh, well that probably reads back in as the correct object but =
won't be true
that says more about =
than it does about prn-str
and edn/read-string
Ah, true. Would have to use a specialized =
to see what else pops up.
(symbol "nil")
is easier to generate than (symbol "true")
I guess
there's a lot more stuff that would come up if gen/any
was more ambitious
e.g., queues, sorted sets, sorted maps, ...