On Thu, Jan 13, 2011 at 4:05 PM, Eduardo Julian <eduardo...@gmail.com> wrote: > I noticed that although you can use assoc with sequences and vectors > to modify them
I get an exception trying to "assoc" a sequence in 1.2. > you could not use dissoc to eliminate elements from > them. Why is this so? Deletion in the middle is not easy with lists or vectors. (Interesting that (dissoc '(1 2 3) 0) and (dissoc [1 2 3] 2) don't work, though; (assoc [1 2 3] 3 4) works to extend by one so why not allow dissoc to contract by one? Although it would just be synonymous with pop. And (assoc '(1 2 3) 0 7) doesn't work, though (cons 7 '(1 2 3)) would do the same thing anyway, and (rest '(1 2 3)) the same as (dissoc '(1 2 3) 0).) Treating a vector as a map from integers to objects, perhaps dissoc could quasi-work on vectors by having (dissoc v n) act like (assoc v n nil); then again, it wouldn't cause (contains? v n) to go from true to false, which people might want from dissoc. It's probably best to leave things as they are. Need to shorten by one? Use pop (vectors) or rest (lists). Need to really dissoc? Use a "sparse vector", that is, an actual map with integer keys, like {0 1, 1 2, 2 3} instead of [1 2 3]. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en