【发布时间】:2016-02-18 15:12:19
【问题描述】:
我在 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}}
我想要重复值的原因是我有两张相同的卡,或多个 nil 值。我使用一个doseq循环遍历这些值,当存在重复时返回一个越界异常。
【问题讨论】: