Re: Idiomatic Way to Write the Following:

2009-02-18 Thread Telman Yusupov
Ahh, this is the best one looking yet! :-) On Feb 18, 1:45 pm, Jeff Valk wrote: > Here's another. > > (defn remove-at [v & idxs] >   (vec (for [i (range (count v)) :when (not ((set idxs) i))] (v i > > - Jeff > And this one is definitely the fastest one: > On Wednesday 18 February 2009 12:0

Re: Idiomatic Way to Write the Following:

2009-02-18 Thread Jeff Valk
Here's another. (defn remove-at [v & idxs] (vec (for [i (range (count v)) :when (not ((set idxs) i))] (v i - Jeff On Wednesday 18 February 2009 12:07, Chouser wrote: > > On Wed, Feb 18, 2009 at 12:30 PM, Telman Yusupov wrote: > > No prettier, but a bit faster: > > (defn remove-at42 [

Re: Idiomatic Way to Write the Following:

2009-02-18 Thread Chouser
On Wed, Feb 18, 2009 at 12:30 PM, Telman Yusupov wrote: > > I'm not sure which version is more idiomatic, but the last one seems > to give me the best performance out of all versions. No prettier, but a bit faster: (defn remove-at42 [coll & indexes] (let [iset (set indexes)] (loop [i (int

Re: Idiomatic Way to Write the Following:

2009-02-18 Thread Telman Yusupov
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 exam

Re: Idiomatic Way to Write the Following:

2009-02-18 Thread Jeff Valk
Vectors are designed for contiguous/sequential data. The case below requires "removing" elements at arbitrary (keyed) locations in a collection. Idiomatically, a map is better suited to the job. With a vector you'll be left reassembling your key. It's worth noting that calling assoc on a vecto

Re: Idiomatic Way to Write the Following:

2009-02-18 Thread James Reeves
On Feb 18, 5:38 am, CuppoJava wrote: > (defn remove_at [coll & indexes] >   (map second >        (remove #(some #{(first %)} indexes) (map vector (iterate inc > 0) coll I'd have thought you could use dissoc, but it seems that only assoc works with vectors. I wonder if this is an oversight or

Re: Idiomatic Way to Write the Following:

2009-02-17 Thread David Nolen
My point was that you could use subvec to do vector splicing and build your remove function off of that. I'm sure the more experienced Clojurians can chime in on what is the most idiomatic form. On Wed, Feb 18, 2009 at 1:10 AM, CuppoJava wrote: > > Mmm, subvec doesn't quite seem to do the same t

Re: Idiomatic Way to Write the Following:

2009-02-17 Thread CuppoJava
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

Re: Idiomatic Way to Write the Following:

2009-02-17 Thread David Nolen
Is using subvec for something like this a bad idea? On Wed, Feb 18, 2009 at 12:38 AM, CuppoJava wrote: > > Hi, > I'm wondering if there's a terser more idiomatic way to write the > following. I want to get a new vector with the specified indexes > removed. I found myself doing this often enough t