2017-05-09 62 views
2

任何人都可以解释,下面的例子有什么问题吗? 它为什么会抛出StackOverflowError异常?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

类似于亚历克斯·米勒在this Google Groups discussion指出,s/+试图定义期间解决::g

这应该做你想要什么,我想:

(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}