On Dec 12, 1:03 pm, Paul Mooser <taron...@gmail.com> wrote:
> On Dec 12, 6:37 am, Rich Hickey <richhic...@gmail.com> wrote:
>
> > I'm appreciate the time you and others have spent on this, and will
> > improve filter, but I'm not sure where you are getting your
> > presumptions about lazy sequences. They are not a magic bullet that
> > makes working with data bigger than memory transparent. They do make
> > it possible in some cases, but that is not their intent. Latent
> > runtime memory consumption is a fact of life of laziness, and is
> > present in Haskell etc. I can make it go away for the specific case of
> > filter and the rest of the library, but not generally.
>
> I think some people have been assuming (perhaps partially motivated by
> my own questions in the initial post regarding the lifetime or extent
> of the caching of lazy-conses), but I actually think an issue that
> seems more fundamental here is being able to state with confidence
> what variables are being closed over and when.
>
> Perhaps it should be obvious to me, but presumably clojure's model is
> not (for example) like scheme's typical simple model of nested
> environments, because in the above example, I'd assume that the lazy-
> cons would capture the environment introduced by let, which presumably
> extends the environment of the when-let, which extends the environment
> of the function which itself includes coll.
>
> Does clojure analyze the expression and close over any bound
> identifiers in the expression? Is that why the version of filter that
> Rich posted works and manages not to capture coll ? Is there any
> documentation for clojure which describes clojure's closure or
> environment semantics, and are there are interactive ways to examine a
> function and determine what it is closing over?
>
> Thanks for your patience - I'm looking forward to understanding
> clojure better.
Clojure has normal lexical scope and closures do what you expect,
although there aren't reified environments like you might find in an
interpreter. Because it uses lazy sequences and doesn't have tail
calls, it does local variable and argument nulling prior to tail
calls, to prevent any lingering references on the stack. In
particular, you can normally hold on to a seq head in a local or
argument and pass it to a tail call without retaining the head.
Closures are lexical and visible, only capturing references from the
enclosing scope actually used in their bodies, not entire
environments, and each individually releasable.
Rich
--~--~---------~--~----~------------~-------~--~----~
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
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
-~----------~----~----~----~------~----~------~--~---