如何在core.logic中解构地图?

Ste*_*gle 3 clojure clojure-core.logic

我相信我在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)))
Run Code Online (Sandbox Code Playgroud)

它返回空列表(),表示它没有找到匹配项.我认为这是代码中(== {:rank a} v)部分的问题.我试图简单地返回q,其中q是地图的矢量:降序排序.

dno*_*len 7

现在可以使用最新的core.logic版本0.8.3编写更简洁的解决方案:

(ns cards
  (:refer-clojure :exclude [==])
  (:use [clojure.core.logic])
  (:require [clojure.core.logic.fd :as fd]))

(def hand
  [{:rank 9, :suit :hearts} 
   {:rank 13, :suit :clubs} 
   {:rank 6, :suit :spades} 
   {:rank 8, :suit :hearts} 
   {:rank 12, :suit :clubs}])

(defn ranko [card rank]
  (featurec card {:rank rank}))

(run* [v w x y z :as q]
  (permuteo hand q)
  (fresh [a b c d e]
    (ranko v a) (ranko w b) (ranko x c)
    (fd/>= a b) (fd/>= b c)
    (ranko y d) (ranko z e)
    (fd/>= c d) (fd/>= d e)))
Run Code Online (Sandbox Code Playgroud)