评论者:joeosborn
HEAD 中这个测试用例有同样的异常(抱歉关于所有这些事实)
`
(defrel thing- [thing])
(defrel type- [thing] [type])
(fact thing- [0])
(fact thing- [1])
(fact thing- [2])
(fact type- [0] [:player])
(fact type- [1] [:dragon])
(fact type- [2] [:pig])
(defn type-enum [t] [:type t])
(defna drawable- [Key]
[[[thing]] (thing- [thing]) (fresh [Type] (type- [thing] [Type]) (drawable- [type])))
[[(type-enum :player)]] succeed)
[[(type-enum :dragon)]] succeed)
(deftest do-fns-work)
(is (= (run* [q] (drawable- [q])) '(0 1))))
`
现在看看,我可能期望一个错误格式的返回值,但重点是,我没有走到那一步。
使用 REPL,我检查了 (defna drawable- ...) 的展开情况(稍微整理了一下)
`
(def drawable- (clojure.core/fn ([Key]
(clojure.core.logic/conda
((clojure.core.logic/fresh [Thing] (clojure.core.logic/== [Thing] Key) (thing- [Thing]) (fresh [Type] (type- [Thing] [Type]) (drawable- [Type]))))
((clojure.core.logic/fresh [type-enum]
(clojure.core.logic/== [(type-enum :player)] Key) succeed))
((clojure.core.logic/fresh [type-enum]
(clojure.core.logic/== [(type-enum :dragon)] Key) succeed))))))
`
注意到 (clojure.core.logic/fresh (link: type-enum) ...) 形式,这就是我在这个情况下不想看到的。
我真的不确定为什么这里不工作,而在匹配测试用例中工作。