Fork me on GitHub
#clojure-spec
<
2018-02-10
>
arohner18:02:02

I’m having trouble generating from a recursive spec, I keep hitting StackOverflowError. Are there any docs/guides on how to do that?

arohner18:02:10

I’m doing:

(s/def ::a a?)
(s/def ::b b?)
(s/def ::c (s/with-gen c? (gen/fmap #(make-c %) (s/or :a ::a :b ::b :c ::c)))

arohner18:02:41

I’ve also tried t.c.gen/recursive-gen

taylor18:02:11

hard to say because the example is missing several definitions but you could try (binding [s/*recursion-limit* 1] ...)

arohner18:02:50

That helped, in that gen/sample occasionally finishes, but still stackoverflows some of the time. It surprised me that in the first 10 items, it produces nested c’s 5 deep, which I wouldn’t expect with a recursion limit of 1

taylor18:02:00

yeah I think there’s been a JIRA ticket w/some discussion about this, can’t find it at the moment

arohner19:02:16

I think I can work around it using gen/frequency

arohner19:02:23

i.e. (gen/frequency [[9 (s/or :a ::a :b ::b)] [1 (s/or :a ::a :b ::b :c ::c]])

arohner19:02:39

frequency helps, but doesn’t completely solve the problem

andy.fingerhut20:02:35

A transcript of a 2-hour talk by Rich Hickey from Dec 2016 about clojure.spec is up now: https://github.com/matthiasn/talk-transcripts/blob/master/Hickey_Rich/ClojureSpec.md

andy.fingerhut20:02:53

It doesn't go deep into the details -- more of an intro, and big picture of ways the pieces of spec can be used.