2016-02-18 1 views
0

У меня проблема с наборами в clojure, где дублирующие значения, по-видимому, удаляются из набора, и это вызывает у меня настоящую головную боль.Использование повторяющихся значений в наборе Clojure

У меня есть карточки.

(def cards 
    { 
    :card1 {:name "Wisp"    :type "Monster"  :damage 1 :health 1 :cost 0 :ability 0} 
    :card2 {:name "Spider Tank"  :type "Monster"  :damage 3 :health 4 :cost 3 :ability 0} 
    :card3 {:name "Boulder Fist Ogre" :type "Monster"  :damage 6 :health 7 :cost 6 :ability 0} 
    :card4 {:name "Bloodfen Raptor" :type "Monster"  :damage 3 :health 2 :cost 2 :ability 0} 
    :card5 {:name "Chillwind Yeti" :type "Monster"  :damage 4 :health 5 :cost 4 :ability 0} 
    :card6 {:name "Magma Rager"  :type "Monster"  :damage 5 :health 1 :cost 3 :ability 0} 
    :card7 {:name "War Golem"   :type "Monster"  :damage 7 :health 7 :cost 7 :ability 0} 
    :card8 {:name "Oasis Snapjaw"  :type "Monster"  :damage 2 :health 7 :cost 4 :ability 0} 
    :card9 {:name "River Crocolisk" :type "Monster"  :damage 2 :health 3 :cost 2 :ability 0} 
    :card10 {:name "Murloc Raider" :type "Monster"  :damage 2 :health 1 :cost 1 :ability 0} 
    :card11 {:name "Northshire Cleric":type "Monster"  :damage 1 :health 3 :cost 1 :ability 2} 


    } 
) 

Эти карточки являются частью набора.

(def board1 (set (map cards '(:card3 :card4 :card11 nil nil nil nil)))) 

Когда я возвращаю этот комплект, я хочу видеть четыре ноль и три карты. Вместо этого я получаю:

#{nil {:ability 0, :name "Bloodfen Raptor", :type "Monster", :damage 3, :health 2, :cost 2} {:ability 0, :name "Boulder Fist Ogre", :type "Monster", :damage 6, :health 7, :cost 6} {:ability 2, :name "Northshire Cleric", :type "Monster", :damage 1, :health 3, :cost 1}} 

Поэтому я хотел бы, повторяющиеся значения в ситуации, в которых у меня есть две одинаковых карт или несколько нулевых значений. Я повторяю эти значения, используя цикл дозыq, который возвращает исключение из пределов, когда присутствуют дубликаты.

ответ

Смежные вопросы