Hi,

On 5 Apr., 01:27, Ken Wesson <kwess...@gmail.com> wrote:

> Oh, and it also doesn't hold onto the head:

Your version of partition-by is basically equivalent to:

(defn partition-by
  [f coll]
  (lazy-seq
    (when-let [s (seq coll)]
      (let [fst          (first s)
            value        (f fst)
            [group tail] (split-with #(-> % f (= value)) (rest s))]
        (cons (cons fst group) (partition-by f tail))))))

It traverses the input sequence twice: once for the take-while, once
for the drop-while. And it does "kind of" hold onto the head. It
doesn't really hold the head, but it still holds references to the
items of the first group, because the (drop-while first ..) is not
executed immediately. Only when the rest is actually realised with
seq, the references to the first group are dropped. So it is a weaker
type of holding the head. That's what I meant with "you would hold
unto the head *in some way*." With some numbers the effect is maybe
not visible, but holding some huge data structures without any notice
why, is maybe a problem.

Sincerely
Meikel

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