Fork me on GitHub
#clojure-spec
<
2017-05-20
>
borkdude19:05:15

Is it possible to express the following in spec: f accepts a function g from string? to int? and it is also possible to generate random instances of g?

borkdude19:05:11

I wondered about this after playing with Quickcheck in Haskell, which can do this

luxbock19:05:33

@borkdude (s/fdef f :args (s/cat :g (s/fspec :args (s/cat :str string?) :ret int?)))

borkdude19:05:58

@luxbock Looks good. How about the generational aspect?

Alex Miller (Clojure team)20:05:22

Gen of fspec is a function that uses its ret generator

stathissideris20:05:56

How would I register (and then use) specs that were generated dynamically? I think I’m at the stage where I need to start property testing spec-provider. To do this I need to generate random data (possible), infer specs for them (that’s what the lib does) and then validate that all the random data are valid for those inferred specs.

Alex Miller (Clojure team)22:05:45

Well you can either call s/def and register your specs or you can just call conform on the specs directly without registering, which works for a lot of stuff