So, clojures vectors behave in a lot of scenarios like associative data structures like records or maps with the indices of the elements as the keys.
get v n will give you the nth element in a vector v
assoc v i e will associate element e at index i in vector v
a famous confuser for newcomers is probably the contains? function which only answers the question if an element is available under a certain key. The famous quote being "contains? is not a rummager". Funnily though it will work on vectors, but do the unexpected thing and look if the vector is large enough to support the index.
So for all intents and purposes vectors in clojure are just associative datastructures, right?
Well, yes. Except where they aren't.
The counterpart for assoc, dissoc, irritatingly doesn't work on vectors and only does work on maps. I find this particularly irritating, as the only real way to "remove" elements from vectors at some index is subvec which does something else entirely. So this sort of behaviour on vectors is sorely missing.
That being said, here is a simple redefinition of dissoc in clojure so that it also works on vectors.
(defn- dissoc-vec
([v index]
(if (get v index)
(vec (concat (subvec v 0 index)
(subvec v (inc index))))
v))
([v key & ks]
(let [n (count v)]
(loop [v v key key ks ks]
(let [diff (- (count v) n)
ret (dissoc-vec v (+ diff key))]
(if ks
(recur ret (first ks) (next ks))
ret))))))
(def dissoc (if| (->| (unapply| first) vector?) dissoc-vec clojure.core/dissoc))