On Oct 27, 4:36 pm, Chris Maier <christopher.ma...@gmail.com> wrote:
> On Wed, Oct 27, 2010 at 10:18 AM, rb <ruzsa.bal...@gmail.com> wrote:
> > P.s. I still don't understand though why the 'calls' argument to the
> > store-calls function is not a held reference to the head of the lazy
> > seq...
>
> I think (and someone please correct me if I'm wrong) that the head of
> 'calls' isn't being retained because you recur on (rest calls),
> replacing your hold on the head with the next item downstream.  Now
> nobody's holding on to the head, so it gets GC'd.  Keep recurring, and
> you just move down the sequence, always dropping what you were holding
> onto, thus allowing it all to be GC'd.
>
> Chris

Yes, this is quite clear in the case of the loop construct:

(loop [calls calls
         conn nil
         stmt nil
         year nil
         month nil]
    (if-let [c (first calls)]
...
(recur (rest calls) conn stmt year month))))

The 'calls' variable bound in the loop is clearly not retained.

What bothers me is the function argument:

(defn store-calls
  [source calls]
...

Here the lazy seq coming in as the second arg is bound to a local
variable named 'calls'. I would think this counts as retainment of the
head of the lazy seq (for the lifetime of the function), but it
apparently doesn't.

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