On Nov 24, 2:41 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> On Nov 24, 12:41 am, "Kevin Downey" <[EMAIL PROTECTED]> wrote:
>
> > I don't think you understand. clojure data structures are IMMUTABLE.
> > every call to conj, or anyother function returns a "new" object. To
> > optimize there is sharing of structure.
>
> In the particular case at hand, i.e. calling vec on a seq, there is no
> structural sharing involved. On the contrary a new Object array of the
> same length as the seq is created. See RT.seqToArray for details.

This is going around in circles.

If you are going to replace every element in a vector, there can be no
sharing with any prior vector, under any method. If you will only
replace a few elements, use reduce. If you are going to replace most
elements, creating a new vector will be more efficient than sharing.
All of these would be true whether or not you had vmap or vfilter.

The seq functions don't change any types etc. They are functions of
collections/seqs to seqs.

Were filter/map etc to return vectors for vectors, then chained
operations would have to return fully-realized intermediate results.
That's wasteful in comparison to the behavior of the seq-based
functions.

Try this:

(def v (vec (range 1000000)))

(defn vmap [f v]
  (into [] (map f v)))

(time (count (vmap inc (vmap inc v))))
user=> "Elapsed time: 1171.923 msecs"

(time (count (into [] (map inc (map inc v)))))
user=> "Elapsed time: 613.164 msecs"

Speculating about inefficiency without a concrete counter-proposal is
not productive. While there could no doubt be some higher-performance
vector constructor/reducers, producing vector-returning versions of
the sequence ops is not generally a good idea.

Rich

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to