I tried to get the results using some clever one liner but couldn't
come up with it. It looks like rolling your own function is the way to
go (but I would love to see this proven wrong).

It would be very helpful if there were a function that does vector
difference, like the one for sets. For example:

(use 'clojure.set)
(defn remove-at2 [coll & indexes]
 (vec (difference (set coll)
             (set (map #(coll %) (vec indexes))))))

could become:

(defn remove-at-hypothetical [coll & indexes]
  (vec-difference coll
              (map #(coll %) (vec indexes))))


Unfortunately, the set version does not maintain the order of elements
in the vector.

Here is the recursive version that does keep the order of elements
intact:

(defn remove-at3 [coll & indexes]
  (loop [idx (vec indexes) result coll]
    (if (empty? idx)
      (vec result)
      (let [current (coll (first idx))
            new-result (if current (remove #(= % current) result) result)]
             (recur (rest idx) new-result)))))

I'm not sure which version is more idiomatic, but the last one seems
to give me the best performance out of all versions.

On Feb 18, 1:10 am, CuppoJava <patrickli_2...@hotmail.com> wrote:
> Mmm, subvec doesn't quite seem to do the same thing.
>
> I want a function that removes certain indexes of a vector:
> eg. (remove_at [1 2 3 4 5 6] 0 3) => [2 3 5 6]
--~--~---------~--~----~------------~-------~--~----~
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
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to