Clojure 如何在core.logic中建模订单关系?
我试图用核心逻辑来模拟有限任务集之间的顺序关系。这就是我到目前为止所做的:Clojure 如何在core.logic中建模订单关系?,clojure,clojure-core.logic,Clojure,Clojure Core.logic,我试图用核心逻辑来模拟有限任务集之间的顺序关系。这就是我到目前为止所做的: (def tasks [:t0 :t1 :t2]) (defn tasko [x] (membero x tasks)) (db-rel before-fact x y) (def facts (db [before-fact :t0 :t1] [before-fact :t1 :t2])) (defn before [x y] (conde [(before-fact
(def tasks [:t0 :t1 :t2])
(defn tasko [x]
(membero x tasks))
(db-rel before-fact x y)
(def facts
(db
[before-fact :t0 :t1]
[before-fact :t1 :t2]))
(defn before [x y]
(conde
[(before-fact x y)]
[(fresh [z]
(tasko z)
(before x z)
(before z y))]))
(defn after [x y]
(before y x))
我运行这个查询:
(with-db facts
(run 3 [q] ; If run with 2, result is correct
(after q :t0)))
目标是只指定数据库中的直接顺序关系(如中所示,1您太接近了!您在before目标的递归步骤中的问题是正确的。将(在x z之前)
更改为(在事实x z之前)
,它应该可以工作
在您提供的版本中,没有语句将z
的值与x
或y
相关,因此程序需要反复检查相同的值