Fork me on GitHub
#clojure-spec
<
2017-08-17
>
didibus01:08:13

Question: Is there a place on a spec you can add a doc-string, so that it is printed when the spec fails?

didibus01:08:46

I would like to have literate english prose explain what the spec predicates are asserting.

seancorfield03:08:04

I believe there's a JIRA issue open to consider docstrings for specs -- but it wouldn't be printed (by default) when a spec failed.

mpenet04:08:29

There s a jira for metadata as well

seancorfield04:08:26

I think better third-party "explain" functions are the right way to go here.

seancorfield05:08:59

(but I think that each application is going to need its own customization so I don't know how much generic goodness we're going to get here)

misha11:08:17

is there builtin predicate for exceptions?

souenzzo17:08:24

I think that "spec is about what you function can do. You shouldn't specify what your function cant do." (under quote cos it's about what I understand when I see the core team talking about spec)

misha11:08:47

(s/def ::throwable #(instance? Throwable %))
?

scaturr14:08:53

I asked this a bit ago but I have yet to stumble upon a solution 🙂 - is there a way to specify a function of arity 1? If i have a function that takes another function as an argument - and that function argument is expected to take a single argument?

scaturr14:08:23

(defn mycool-func [fn1-handler] ...)

scaturr14:08:36

how would I spec mycool-func?

scaturr14:08:52

I’ve just been using fn? until I learn what a computer is

gfredericks14:08:34

something like (fspec :args (s/cat any?))

Alex Miller (Clojure team)19:08:46

(s/fspec :args (s/cat :x any?))

scaturr14:08:31

@gfredericks I’ll give that a whirl. Thank you!

samueldev15:08:42

how can I check if something is a spec?

samueldev15:08:51

I am writing a DSL and one of the values needs to be a clojure.spec

samueldev16:08:56

I'm opting for (s/get-spec) for my problem

joshmiller17:08:35

Is there an equivalent to s/describe for fdef‘ed fns?

souenzzo18:08:08

"(s/describe `rules.core/rules-in-eid)"works for me

joshmiller18:08:20

Oh, duh, I didn’t quote the fn name so it evaluated it. Thanks!

Alex Miller (Clojure team)19:08:04

also note that (doc rules.core/rules-in-eid) will print the function specs

Alex Miller (Clojure team)19:08:21

as part of the docstring

Alex Miller (Clojure team)19:08:43

doc also knows about specs so (doc ::foo) works for data specs

joshmiller20:08:30

Oh awesome, didn’t know about that either. Thanks!

souenzzo21:08:50

(s/cat :foo string? :bar (s/spec (s/cat :barbar string?))) is it right? there is a shorter way? I'm not sure if s/spec + s/cat is right ["foo string" ["barbar string"]] << sample

joshjones21:08:36

:thumbsup::skin-tone-2: ^^

bfabry21:08:51

@souenzzo the second half could be (s/tuple string?) if you are specifically expecting a vector of length 1

souenzzo21:08:00

But tuple is some kind of anonymous Thinking in docs (in my case, the main propose), give a name for the elements of the tuple is better...

souenzzo21:08:57

(in the real case, it's a tuple 3 elements where each is a different tuple of 3 elements)

bfabry22:08:09

aye, it's very dependent on your use case. with that much nesting I'd say names could definitely be helpful

bfabry21:08:55

(without the need for wrapping in s/spec)