Fork me on GitHub
#clojure-spec
<
2019-01-28
>
jeroenvandijk09:01:32

@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)
      )))))

borkdude09:01:06

@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

borkdude09:01:30

I’ll probably give up on it for now. CLJS has plenty of similar issues like this (instrumenting apply, seq, etc.)

borkdude09:01:44

I’m not sure what your solution accomplishes, but you could add it to the issue with some context

jeroenvandijk10:01:53

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

borkdude10:01:14

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.

jeroenvandijk10:01:41

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.

borkdude10:01:28

that would be the more fundamental solution yes

borkdude10:01:10

it would also speed up core instrumentation probably

butterguns17:01:56

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?