3

Can anybody explain, what's wrong with the example below? Why does it throw the StackOverflowError exception?

(s/def ::tag keyword?)
(s/def ::s string?)
(s/def ::n number?)
(s/def ::g
  (s/cat :tag (s/? ::tag)
         :ex (s/alt :string ::s
                   :number ::n
                   :and (s/+ ::g)
                   )))


(s/conform ::g '["abc"])

1 Answer 1

4

Similarly to what Alex Miller points out in this Google Groups discussion, s/+ tries to resolve ::g during the definition.

This should do what you want, I think:

(s/def ::g
       (s/spec (s/cat :tag (s/? ::tag)
                      :ex (s/alt :string ::s
                                 :number ::n
                                 :and ::g))))

; REPL
user=> (s/conform ::g [:foo [:bar "abc"]])
{:ex [:and {:ex [:string "abc"] :tag :bar}] :tag :foo}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.