On 21 April 2010 20:09, Mark Engelberg <mark.engelb...@gmail.com> wrote:
> In some languages, split-at is more performant than doing take and
> drop separately.  But in Clojure, split-at is simply defined as:
> (defn split-at
>  "Returns a vector of [(take n coll) (drop n coll)]"
>  [n coll]
>    [(take n coll) (drop n coll)])
>
> So by using split-at, you gain nothing other than the additional
> overhead of constructing a vector and then turning around and
> destructuring it.

I realise that, however I find that there is also a slight gain in
readability / aesthetic appeal of the code; buying that at the minute
cost incurred due to creating and destructuring a vector seems
acceptable to me.

As an aside, it might actually be possible to write a more efficient
split-at -- perhaps exploiting the nature of the sequence being split
(e.g. you could use (seq (subvec ...)) with vectors) -- should the
need arise, so maybe it will become beneficial from the performance
POV at some point...

Sincerely,
Michał

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