Fork me on GitHub
#clojure-spec
<
2019-08-14
>
murtaza5204:08:35

just trying to understand why does a empty seq satisfy this spec (s/valid? (s/every integer?) []), shouldn’t it fail ?

alexmiller04:08:06

because every element in the collection is an integer

alexmiller04:08:14

for all none elements

murtaza5205:08:59

could you please expand on none elements, did not grasp it

alexmiller06:08:11

(s/every? integer?) specifies a collection where each element is an integer. In this case [] meets that spec, there just happen to be no elements.

murtaza5206:08:01

thanks @U064X3EF3 that explains it

murtaza5205:08:23

When I run (stest/summarize-results (stest/check)), I see the following error printed in my repl - No implementation of method: :specize* of protocol: #'clojure.spec.alpha/Specize found for class: nil all the tests are passing and the :sym names are being printed correctly, however at the end it prints the above too.

alexmiller06:08:49

don't know, can't tell from just that

kenny15:08:57

I get this often. Typically it's from forgetting to call s/gen on a spec.

murtaza5215:08:47

There was a typo in my s/fdef association with the sym, once that was corrected, the error disappeared

alexmiller06:08:11

(s/every? integer?) specifies a collection where each element is an integer. In this case [] meets that spec, there just happen to be no elements.

alexmiller06:08:53

if you require a non-empty collection, you can use (s/every? integer? :min-count 1)

ataggart21:08:19

conformer doc states: > takes a predicate function with the semantics of conform i.e. it should return either a (possibly converted) value or :clojure.spec.alpha/invalid And yet defining such a function gives me an error (minimal reproducible example):

user=> (defn f [] :clojure.spec.alpha/invalid)
Syntax error macroexpanding clojure.core/defn at (/private/var/folders/m9/5hxwnkyj0bxf6plprrbf5vzw0000gn/T/form-init9446902011342467351.clj:1:1).
:clojure.spec.alpha/invalid - failed: map? at: [:fn-tail :arity-1 :body :prepost+body :prepost] spec: :clojure.core.specs.alpha/defn-args
:clojure.spec.alpha/invalid - failed: any? at: [:fn-tail :arity-1 :body :body] spec: :clojure.core.specs.alpha/defn-args
Am I missing something silly?

alexmiller21:08:41

defining that function fails the spec for defn itself

alexmiller21:08:59

as it has the magic "invalid" value

alexmiller21:08:31

a workaround is

alexmiller21:08:33

user=> (def i :clojure.spec.alpha/invalid)
#'user/i
user=> (defn f [] i)
#'user/f

ataggart22:08:14

I think I have managed to avoid running into this by having predicates before the conformer (surrounded by s/and), thus obviating the need for the forming fn to explicitly yield ::s/invalid.