Search code examples
clojure

How can I remove an element in Clojure?


I think my code is on the right track, but I am either missing something or overlooking the solution. I want to remove an element from the list and it is somewhat doing it but not in the way that I want it. Here is my code:

(defn removeLetter [x y]
(remove #{y} (list x)) 
  )

(println (removeLetter '(w x y z) 'w))

This outputs ((w x y z)) when I want it to output (x y z). How can I fix my code?


Solution

  • list doesn't convert its argument into a list - instead, it accepts any amount of arguments and returns a list containing those values.

    You can simply replace (list x) with just x and it should work then.