Skip to content

Instantly share code, notes, and snippets.

@bhb

bhb/repl.txt

Created Sep 25, 2018
Embed
What would you like to do?
Confusing behavior from `keys*`
➜ ~ rlwrap clj -Srepro -Sdeps '{:deps {org.clojure/spec.alpha {:mvn/version "0.2.176"}}}'
Clojure 1.9.0
user=> (require '[clojure.spec.alpha :as s])
nil
user=> (s/def ::point1 (s/cat :x int? :y int?))
user/point1
user=> (s/def ::x int?)
:user/x
user=> (s/def ::y int?)
:user/y
user=> (s/def ::point2 (s/keys* :req-un [::x ::y]))
:user/point2
user=> ;; for `cat` spec, `in` will refer to the position before conformance
user=> (s/explain ::point1 [0 nil])
nil - failed: int? in: [1] at: [:y] spec: :user/point1
nil
user=> ;; but for `keys*` spec, `in` will refer to position AFTER conformance
user=> (s/explain ::point2 [:x 0 :y nil])
nil - failed: int? in: [:y] at: [:y] spec: :user/y
nil
user=>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment