Fork me on GitHub
#clojure-spec
<
2018-09-16
>
ikitommi06:09:25

From reddit: > There are a couple areas (spec programmability and some map-related stuff) where we have some work to do.

ikitommi06:09:19

sounds good, despite doesn't say much about what kind of changes. As there are lot of libraries trying to extend spec for different use-cases, it would be great if the need of the libs could be taken into account. Personally would like to see some public spec walking protocols.

ikitommi07:09:53

and not based on a parsing spec forms, that we can do outside, more like CLJ-2251.

ikitommi07:09:02

a library developer feature poll/discussion?

misha07:09:45

@richiardiandrea you can create ns and give it an alias, it will not be tied to an actual file, but you will be able to use that alias to shorten keywords. it is not pretty though. clojure.core/create-ns, clojure.core/alias. I found, that having shorter spec names is less tedious and more readable (possible in app layer, where your system is pretty much the only system which sees them). In libraries you probably would want to use longer "truly" global long keywords for under the hood things.

richiardiandrea15:09:20

This is an interesting idea, but feels like a hack :) I will give it a try anyways, thank you!

misha16:09:23

this is sort of what ns does, but it looks alien and hacky, I agree with that.

richiardiandrea18:09:12

unfortunately alias does not seem to work in cljs

misha18:09:57

i'd cross-post this to #clojurescript, seems critical(?)

richiardiandrea18:09:21

done that

đź‘Ť 4
Ho0man08:09:59

Hi, I am using spec for the first time. And it takes too long to generate my specs using (test.check/generate (spec/gen ,,, )). I had previously used test.check for similar data generation and did not had the problem. The spec if the configuration map having many nested spec/keys and spec/every. Limitin spec/every with :gen-max did not help. What am I doing wrong ?

Ho0man08:09:41

Heres part of the spec ... the final configuration contains a numbeer of :ecosystem/service-instances

Alex Miller (Clojure team)12:09:02

If you have a lot of s/every, they will gen up to 20 elements. Setting :gen-max in those to something like 3 would probably help

Ho0man07:09:55

Thanks, Alex. I did try that and it helped. My question is whether there is a fundamental difference in spec's data generation and that of test.check's ? And should I be concerned about using these specs in large generative tests as their size grows ? Thanks again

Alex Miller (Clojure team)12:09:07

spec uses test.check generators so there is literally no difference. There will always be the need to tune the gens a little bit

dadair18:09:48

What’s the preferred way of specing a spec? I have an internal lib function that takes a spec and I want the s/fdef to check that the arg is a spec. So far I have qualified-keyword? But that’s a bit of a shallow spec? Tried spec? But it was returning false on s/def’d qualified keys.

dadair18:09:30

That spec arg is later used in internal machinery to validate some request routing

seancorfield18:09:30

@dadair Remember that a predicate function could also be (treated as) a spec...

dadair18:09:56

Yeah, at this point I force using a “defined” spec

seancorfield18:09:23

Maybe call s/form on it and succeed if you get truthy?

dadair18:09:14

Maybe expect users to wrap in (s/spec ..) prior to passing argument, then internally spec against s/spec??

dadair18:09:11

that would also get around the limitation of removing the ability to use a raw predicate

dadair18:09:19

Are there any downsides to that approach? I’m not super familiar with the effects of (s/spec ..)

seancorfield18:09:24

There's a get-spec function you can use with the qualified keyword (rather than s/form). You can wrap anything in s/spec: (s/spec 42)

seancorfield18:09:13

So (s/spec? (s/spec 42)) is truthy -- so it won't tell you it's really a spec that is wrapped.

dadair18:09:59

Yeah maybe I need to do some code-based validation rather than relying on the fdef here

dadair18:09:52

It’s not a critical check, I’m just trying to add some guardrails for the other devs that aren’t super familiar with this part of the system

seancorfield18:09:54

I guess I'd take a step back and ask: Am I over-constraining this function?

seancorfield18:09:28

Can it accept a predicate and use it like a spec, for example?

dadair18:09:02

Yeah, that’s what I’m thinking too.

Alex Miller (Clojure team)18:09:11

specs can be qualified-keyword?, set?, ifn?, or spec instances (there’s a s/spec? for those)

đź‘Ť 4
samedhi20:09:29

Should I be using (spec/fdef ...) for multimethods (does not seem to work)? Guess I can just wrap the defmulti invocation in a function and test that...

samedhi20:09:19

Erroneously thought that multi-spec was for multimethods, but it actually appears to be for dispatching data based on "kinds".

samedhi20:09:08

nm, silly ns error. spec/fdef does appear to work with defmulti