On Sep 23, 3:02 pm, F Lengyel <florian.leng...@gmail.com> wrote: > On Sep 23, 2:20 am, Kevin Livingston > > <kevinlivingston.pub...@gmail.com> wrote: > > what's the actual use case where you want this? > > it seems pretty weird just on it's own. it may in practice be more > > clever than other solutions, but that's not clear yet. if you just > > want a unique symbol there's (gensym) > > For the sake of illustration, this function will chunk a vector into > vectors of identical elements, in order (no assurance that it won't > be weird in context): > > (defn grp [s] > (-> (reduce > (fn [[v chunk] elt] > (if (or (empty? chunk) (= elt (first chunk))) > [v (conj chunk elt)] > [(conj v chunk) [elt]])) > [[][]] (conj s s)) > (first)))
(partition-by identity s) is simpler unless you have some very compelling reason to need vectors? > > user> (grp []) > [] > user> (grp [1 2 3 2 2 3]) > [[1] [2] [3] [2 2] [3]] > user> (grp [1 1 4 4 4]) > [[1 1] [4 4 4]] > user> > > > regarding vectors, I found this a helpful read a while back, it's a > > few years old, but I think it's still accurate, and may help you get a > > picture of what's under the > > hood.http://blog.higher-order.net/2009/02/01/understanding-clojures-persis... > > > Kevin > > That's helpful, thank you. -- 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