clojure.spec conform引发堆栈溢出异常
有人能解释一下,下面的例子有什么问题吗? 为什么会抛出StackOverflowerr异常clojure.spec conform引发堆栈溢出异常,clojure,clojure.spec,Clojure,Clojure.spec,有人能解释一下,下面的例子有什么问题吗? 为什么会抛出StackOverflowerr异常 (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/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"])
与Alex Miller在中指出的类似,
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}