This reminds me, is there anything in contrib that works like Scheme's
build-vector which works like:
(build-vector n f) produces (vec (map f (range n))), i.e., [(f 0) (f
1) (f 2) ... (f (dec n))]   ?

It would be great if someone's already tested a few variations of this
fairly useful function to find the fastest way to code it, but I would
guess that it is something like (untested):
(defn build-vector [n f]
  (let [n (int n)]
    (loop [i (int 0) v (transient [])]
      (if (= i n)
        (persistent! v)
        (recur (inc i n) (conj! v (f i)))))))

With something like this, (vector-of n value) could be written as
(build-vector n (fn [_] value))

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to