【发布时间】:2013-05-04 03:37:30
【问题描述】:
我正在尝试在clojure.core.logic 中实现与membero 相反的功能,但它返回的是两个值而不是一个。否则,它可以正常工作(当值在列表中时不返回任何内容,当不在列表中时返回)。
(defne nonmembero
"A relation where l is a collection, such that l does not contain x"
[x l]
([_ ()])
([_ [head]]
(!= x head))
([_ [head . tail]]
(!= x head)
(nonmembero x tail)))
示例运行:
user> (run* [x] (nonmembero 1 [2 3 4 5]))
(_0 _0)
user> (run* [x] (nonmembero 1 [2 3 1 4 5]))
()
【问题讨论】:
标签: clojure clojure-core.logic