2010/12/29 Ken Wesson <kwess...@gmail.com> > 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 {}. >
To the risk of repeating myself and not having totally understood your above explanation, worded differently : when I see (reduce insert-into [] s) with [] in the 'val' position, I use this as a hint on what the resulting val returned by reduce will be. If we're ok with the above reasoning, then I find that [] implies the result will be a datastructure (and a vector datastructure, to be even more precise IMHO). While I see the () value as more "neutral" (though not ideal as you said, but still better than [] in the particular case). -- 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