谁能解释一下,下面的例子有什么问题? 为什么会抛出 StackOverflowError 异常?
(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 在 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}
关于clojure.spec conform 抛出堆栈溢出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43868064/