我知道project
在 core.logic 中是不相关的。
但是,似乎我可以通过在内部的两个方向投影来获得类似关系的行为conda
,例如:
(defn lifto-with-inverse
"Lifts a unary function and its inverse into a core.logic relation."
([f g]
(fn [& vs]
(let [[x y] vs]
(conda
[(pred x number?) (project [x] (== y (f x)))]
[(pred y number?) (project [y] (== x (g y)))])))))
(let [inco (lifto-with-inverse inc dec)]
(run* [q] (inco q 3)))
=> 2
这算作关系操作吗?还是缺少其他东西使这种非关系性?