Hi,
I am struggling with recursive Spec declarations, more in particular how
two Spec definitions can refer to each other. In the example below, I use a
"forward" declaration, but that does not seem very elegant. Am I missing
something?
The more fundamental question, however, is how to implement recursion
limits. After several recursive iterations during generation, I would like
to force the use of non-recursive elements (leafs in the example below), to
avoid stackoverflows. However, I am struggling to see how a recursion limit
can be implemented.
Example code:
; "Forward" declarations of specs
(s/def ::Tree ::s/any)
(s/def ::Leaf ::s/any)
(s/def ::name string?)
(s/def ::children (s/coll-of (s/or :tree ::Tree, :leaf ::Leaf)))
(defrecord Tree [name children])
(defrecord Leaf [name])
(s/def ::Leaf (s/with-gen
(s/keys :req-un [::name])
#(gen/let [name (s/gen ::name)]
(->Leaf name))))
(s/def ::Tree (s/with-gen
(s/keys :req-un [::name ::children])
#(gen/let [name (s/gen ::name)
children (s/gen ::children)]
(->Tree name children))))
When trying to generate a Tree (gen/generate (s/gen ::Tree)), a
Stackoverflow is produced.
I am aware of a bug report (http://dev.clojure.org/jira/browse/CLJ-1964),
but that report was closed by Alex Miller due to the changes in Alpha8.
(BTW, the sample code in that bug report still produces a stackoverflow in
Alpha8, despite Alex' suggestion that it should now work).
Any ideas?
Best regards,
Maarten
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.