Fork me on GitHub
#clojure-spec
<
2017-11-06
>
dominicm13:11:49

@drewverlee I think the human error messages also need to include a location which is separate from their spec position. Sometimes you need to do validation across keys for humans, but place the error message on a particular key (password & password_confirm must match, but if they don't, the error is in password_confirm)

seako18:11:40

i find them noisy and like that test.chuck turns them off when using the checking macro

Drew Verlee16:11:02

Is there a rational for the :reason key in the problem map produced by spec/explain-data?. I cant find any discussion on it

Drew Verlee20:11:42

is there a function that you can call on a spec to get the code for the spec?

(s/data some-spec) 
;;=> (s/def ::some-spec string?)

taylor20:11:56

(s/form some-spec) in your example should work @drewverlee

Drew Verlee20:11:58

It seems to only return part of the spec.

(s/def ::kid (s/keys ::req [::name]))
(s/form ::kid) 
;;> (spec/keys)

taylor20:11:49

I think that keys spec is invalid

taylor20:11:02

try :req instead of ::req

Drew Verlee21:11:12

Hmm, how about something similar for spec functions? those defined using fdef?

taylor21:11:57

(s/form `foo)
where foo is your function

Drew Verlee16:11:52

How does that work? backtick stops evaluation of things and qualifies their namespace. Why does that help?

taylor16:11:24

> However, symbols used within a syntax quote are fully resolved with respect to the current namespace

taylor16:11:09

(defn foo [x] x)
=> #'sandbox.core/foo
foo
=> #object[sandbox.core$foo 0x111da369 "sandbox.core$foo@111da369"]
`foo
=> sandbox.core/foo
(type foo)
=> sandbox.core$foo
(type `foo)
=> clojure.lang.Symbol

Drew Verlee16:11:20

gotcha. I was actual experiencing another mis understanding the same time concerning lists.

taylor21:11:40

s/fdef is using s/def “behind the scenes” to register the spec to the function symbol, so you can use the function symbol to resolve the spec (instead of a namespaced keyword)