Clojure core.logic kullanarak bir haritadan veri çekmeye çalışıyorum. Ben haritaya diğer bazı unsurlar eklemek o zaman eşleştirememişse AncakClojure core.logic'ten bir haritanın öğeleri çıkarma
(run 10 [q]
(fresh [?id ?type ?name]
(membero ?type [:t2 :t1])
(== q [?id ?name])
(membero {:id ?id :type ?type :name ?name}
[
{:id 1 :type :t1 :name "one"}
{:id 2 :type :t2 :name "two"}
])))
=> ([2 "two"] [1 "one"])
:
(run 10 [q]
(fresh [?id ?type ?name]
(membero ?type [:t2 :t1])
(== q [?id ?name])
(membero {:id ?id :type ?type :name ?name}
[
{:id 1 :type :t1 :name "one" :other1 :o1}
{:id 2 :type :t2 :name "two" :other2 :o2}
])))
neden matcho
haritalar gibi çalışmıyor anlamaya hayır bu kod ben bunu istediğiniz gibi yapar aynı daha uzun. Benim quesiton'um, bunu nasıl değiştirebilirim ki tekrar çalışır? Bir haritadaki tuşların bazılarında eşleşmesini nasıl sağlayabilirim veya haritanın sahip olabileceği rasgele anahtarlarla eşleşmesini nasıl sağlayabilirim?
DÜZENLEME: (https://github.com/clojure/core.logic/pull/10 sayesinde) patial-map
kullanarak çalışmak got it
(run 10 [q]
(fresh [?id ?type ?name]
(membero ?type [:t2 :t1])
(== q [?id ?name])
(membero (partial-map {:id ?id :type ?type :name ?name})
[
{:id 1 :type :t1 :name "one" :other1 :o2}
{:id 2 :type :t2 :name "two" :other2 :o1}
])))
Ancak
featurec
yerine
partial-map
arasında kullanılması gerektiğini bir not buldum. Yeni sorum:
featurec
'u kullanmak için bunu nasıl değiştirebilirim? Kendi sorumu yanıtlayan
Kullandığım test kodunun bir Özeti ekledim: https://gist.github.com/4454548 –