Re: Clojure vectors

2009-07-16 Thread Daniel
On Thu, Jul 16, 2009 at 1:52 AM, John Harrop wrote: > On Wed, Jul 15, 2009 at 12:58 PM, Mark Engelberg > wrote: >> >> It looks like stack-rot is going to be the bottleneck in your app >> since it requires traversing the whole vector to build the new one, >> but I think the list-based implementati

Re: Clojure vectors

2009-07-15 Thread John Harrop
On Wed, Jul 15, 2009 at 12:58 PM, Mark Engelberg wrote: > > It looks like stack-rot is going to be the bottleneck in your app > since it requires traversing the whole vector to build the new one, > but I think the list-based implementation would be a bit worse, so I > think your choice to use vecto

Re: Clojure vectors

2009-07-15 Thread Chouser
On Wed, Jul 15, 2009 at 6:00 PM, Mark Engelberg wrote: > > On Wed, Jul 15, 2009 at 9:58 AM, Mark Engelberg > wrote: >> The problem with subvec is that it doesn't really create a "new" >> vector, it just adds a level of indirection off of the original >> vector.  So for example, if you look up, sa

Re: Clojure vectors

2009-07-15 Thread Mark Engelberg
On Wed, Jul 15, 2009 at 9:58 AM, Mark Engelberg wrote: > The problem with subvec is that it doesn't really create a "new" > vector, it just adds a level of indirection off of the original > vector.  So for example, if you look up, say, index 2 in the subvec, > it knows to go look up index 5 in the

Re: Clojure vectors

2009-07-15 Thread Mark Engelberg
On Wed, Jul 15, 2009 at 3:51 AM, Jan Rychter wrote: > I am not sure what you mean about subvecs, though -- I currently use > them for dropn and rot operations, and I don't know how to avoid using > them: The problem with subvec is that it doesn't really create a "new" vector, it just adds a level

Re: Clojure vectors

2009-07-15 Thread Jan Rychter
Thanks to everyone who replied in this thread. I am impressed by the signal-to-noise ration on this list and by the quality of replies. I will try to reply to everyone in a single post, trying to summarize. > On Jul 13, 11:15 am, Jan Rychter wrote: >> I've been trying to implement stacks using v

Re: Clojure vectors

2009-07-13 Thread stephaner
Hi Instead of: (conj (drop-last 1 [1 2 3]) 4) You could use into []: (conj (into [] (drop-last 1 [1 2 3])) 4) [1 2 4] Stephane _/) On Jul 13, 11:15 am, Jan Rychter wrote: > I've been trying to implement stacks using vectors in Clojure. In case > you wonder why, it's because I need stacks w

Re: Clojure vectors

2009-07-13 Thread Rob
On Jul 13, 11:15 am, Jan Rychter wrote: > I've been trying to implement stacks using vectors in Clojure. In case > you wonder why, it's because I need stacks with a fast item count > operation. If that's the only reason, you don't have to use vectors. The following page says that 'count' for

Re: Clojure vectors

2009-07-13 Thread Chouser
On Mon, Jul 13, 2009 at 11:15 AM, Jan Rychter wrote: > > However, after reading "Programming Clojure" (page 114) I expected to be > able to use sequence functions, such as drop-last, without my vectors > changing representation. It seems this is not the case, as after calling > drop-last (or indee

Re: Clojure vectors

2009-07-13 Thread Mark Engelberg
On Mon, Jul 13, 2009 at 8:15 AM, Jan Rychter wrote: > And while we're on the subject -- any hints for implementing a stack > with a fast item count? (apart from a list with a separate counter) Using conj and pop on vectors for stack operations should work just fine. Don't use subvec though; nest

Re: Clojure vectors

2009-07-13 Thread Kevin Downey
the sequence functions operate on sequences. if you pass in something that is not a sequence, like a vector, they call seq on it internally. so what you get back from filter or map is a sequence. conj has consistent behavior across types, you just get a different type out of map/filter/etc then wh