我想在以下示例代码中从[:b :B]
中删除[[:a :A] [:b :B] [:c :C]]
,如果我将:B
替换为(lvar)
,则不再有效:
;; Helper Function
(defne not-membero [x l]
([_ []])
([_ [?y . ?r]]
(!= x ?y)
(not-membero x ?r)))
这些工作:
(run* [q]
(membero q [[:a :A] [:b :B] [:c :C]])
(not-membero q [[:b :B]]))
(run* [q]
(membero q [[:a :A] [:b :B] [:c :C]])
(!= q [:b :B]))
;; both return [[:a :A] [:c :C]], as expected
这些不(注意lvar
):
(run* [q]
(membero q [[:a :A] [:b :B] [:c :C]])
(not-membero q [[:b (lvar)]]))
(run* [q]
(membero q [[:a :A] [:b :B] [:c :C]])
(!= q [:b (lvar)]))
;; both return [[:a :A] [:b :B] [:c :C]], unexpected
答案 0 :(得分:0)
我认为在您的示例中不起作用的原因是创建的(lvar)
未绑定/与程序中的任何其他逻辑变量无关。如果你使用fresh
逻辑变量,你的程序运行正常(至少我认为这是你想要的):
(run* [q]
(fresh [x]
(membero q [[:a :A] [:b x] [:c :C]])
(not-membero q [[:b x]])))
=> ([:a :A] [:c :C])
(run* [q]
(fresh [x]
(membero q [[:a :A] [:b x] [:c :C]])
(!= q [:b x])))
=> ([:a :A] [:c :C])
或者,这些返回相同的结果,而不知道元组中的:b
项:
(run* [q]
(fresh [x]
(membero q [[:a :A] x [:c :C]])
(not-membero q [x])))
(run* [q]
(fresh [x]
(membero q [[:a :A] x [:c :C]])
(!= q x)))