2017-05-09 3 views
2

誰でも説明できますが、下の例で何が問題になっていますか? StackOverflowError例外がスローされるのはなぜですか?アレックス・ミラーは、定義時に::gを解決しようとs/+this Google Groups discussionで指摘したものと同様clojure.spec適合はスタックオーバーフロー例外をスローする

(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"]) 

答えて

4

これは、あなたが欲しいものを行う必要があり、私は思う:

(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} 
関連する問題