Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using disj to remove an element from a set in Clojure

Tags:

set

clojure

Hi I've hit a brick wall whilst trying to remove an element from a set.

I have a map of cards.

   (def cards
  {
    :card1 {:name "Wisp"              :type "Monster"     :damage 1 :health 1 :cost 0 :charge "t"}
    :card2 {:name "Spider Tank"       :type "Monster"     :damage 3 :health 4 :cost 3}
    :card3 {:name "Boulder Fist Ogre" :type "Monster"     :damage 6 :health 7 :cost 6}

    }
 )

And a deck (set) of these cards.

(def deck1 (set (map cards '(:card1 :card2 :card3))))

When I use disj to try and remove one of these cards nothing happens.

(disj deck1 :card1)

I really have no idea why.

like image 852
JT93 Avatar asked Sep 06 '25 07:09

JT93


1 Answers

leetwinski was right in the comments. (disj deck1 (:card1 cards)) is correct.

like image 81
JT93 Avatar answered Sep 08 '25 01:09

JT93



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!