This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-01-28
Channels
- # announcements (5)
- # aws (16)
- # beginners (62)
- # calva (2)
- # cljdoc (17)
- # cljs-dev (2)
- # clojure (89)
- # clojure-brasil (1)
- # clojure-europe (3)
- # clojure-italy (12)
- # clojure-nl (1)
- # clojure-russia (2)
- # clojure-spec (10)
- # clojure-uk (26)
- # clojurescript (45)
- # cursive (4)
- # data-science (6)
- # datavis (1)
- # datomic (15)
- # duct (5)
- # fulcro (55)
- # juxt (1)
- # kaocha (2)
- # leiningen (1)
- # off-topic (101)
- # pathom (12)
- # portkey (4)
- # quil (5)
- # re-frame (9)
- # reagent (2)
- # reitit (28)
- # shadow-cljs (114)
- # spacemacs (9)
- # speculative (2)
- # sql (3)
- # test-check (18)
@borkdude maybe something ugly as this would work:
(let [hash-map0 (var-get #'hash-map)]
(alter-var-root #'clojure.core/hash-map (constantly (fn [& x]
(with-redefs [clojure.core/hash-map hash-map0]
;; validation here?
(apply clojure.core/hash-map x)
)))))
@jeroenvandijk if you’re interested, I have a potential fix for hash-map not being able to be instrumented here: https://github.com/borkdude/speculative/issues/264
I’ll probably give up on it for now. CLJS has plenty of similar issues like this (instrumenting apply, seq, etc.)
I’m not sure what your solution accomplishes, but you could add it to the issue with some context
From what I understand, hash-map
calls hash-map
itself when instrumented. So I thought of aliasing hash-map
to the old version of hash-map
during the validation itself. Just an idea, maybe it's shortsighted
right. the spec-checking-fn replacing hash-map calls itself (because binding emits a call to hash-map), so it ends up in a loop.
Maybe a complete clojure.core
fix would be to have (stest/instrument x)
to have x
to be aliased to it's previous value so it cannot interfere with the instrumentation itself when x
is used for the instrumentation.
Hi. I'm experimenting with Spec. I think I'm approaching it (incorrectly) from an OO background. Suppose I have a spec ::vehicle #{:car :truck :semi-truck :bicycle :motorbike}
. It is part of a map (s/keys :req [::vehicle ::color])
.
At some time later in processing, I have a function that requires 2-wheeled vehicles, so I might have ::two-wheeled-vehicle (s/and ::car has-two-wheels?)
.
My problem is I've already used the ::vehicle
key for the more "generic" specification of a vehicle. I would need to create a new map with new keys (`(s/keys :req [::two-wheeled-vehicle ::color])`), and copy all the values over, in order to validate the stricter specification. Am I doing it wrong?