我相信我在解构 core.logic 中的地图时遇到了麻烦。我有以下代码:
... used clojure.core.logic
... required clojure.core.logic.arithmetic as logic.arithmetic.
(def hand ({:rank 9, :suit :hearts}
{:rank 13, :suit :clubs}
{:rank 6, :suit :spades}
{:rank 8, :suit :hearts}
{:rank 12, :suit :clubs}))
(run* [q]
(fresh [v w x y z] ;;cards
(== q [v w x y z])
(membero v hand)
(membero w hand)
(membero x hand)
(membero y hand)
(membero z hand)
(fresh [a b c d e] ;;ranks
(== {:rank a} v)
(== {:rank b} w)
(== {:rank c} x)
(== {:rank d} y)
(== {:rank e} z)
(logic.arithmetic/>= a b)
(logic.arithmetic/>= b c)
(logic.arithmetic/>= c d)
(logic.arithmetic/>= d e))
(distincto q)))
它返回空列表(),表明它没有找到匹配项。我相信这是代码的 (== {:rank a} v) 部分的问题。我试图简单地返回 q,其中 q 是按 :rank 降序排列的地图向量。