On Wed, Dec 29, 2010 at 11:55 AM, Laurent PETIT <laurent.pe...@gmail.com> wrote: > > > 2010/12/29 Ken Wesson <kwess...@gmail.com> >> >> On Wed, Dec 29, 2010 at 11:42 AM, Laurent PETIT <laurent.pe...@gmail.com> >> wrote: >> > 2010/12/29 Ken Wesson <kwess...@gmail.com> >> >> (defn insert-into [s x] >> >> (let [[low high] (split-with #(< % x) s)] >> >> (concat low [x] high))) >> >> >> >> (defn insertion-sort [s] >> >> (reduce insert-into [] s)) >> > >> > Hello, just a little 0.00002€ : insert-into will return seqs, so the >> > reduce >> > could read : >> > (reduce insert-into () s) >> > to make it clear that it's seqs end to end inside insertion-sort >> >> It's my habit to use a vector for any "seq literal". >> >> How about I split the difference? >> >> (reduce insert-into nil s) >> >> seems to work just as well. :) > > Yeah, not a big deal, it's just that by just reading the line (reduce > insert-into [] s), I see the initial "collected value" is a vector, and I > make an assumption about insert-into to return vectors as well.
Eh? I don't. I tend to only assume "it takes seqables" if I see vector literals going into something. If it's a reduction, I presume the function being reduced to return seqables as well. My preference here is for the empty vector: * The empty list () is odd. In Clojure usually parentheses wrap an executable expression, not just data. * Quoting it -- '() -- is just plain ugly. * The value nil can generally stand in for an empty seq, but has other unrelated meanings as well. * The empty vector is, explicitly, a zero-length seqable piece of inert data. * So is the empty set #{}, but it's commonplace to use vector literals as "seq literals", so an empty vector is less confusing. My objection to the empty set is the same as yours to the empty vector. * That goes double for the empty map {}. -- 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