>> This statement is ironic, considering the definition of a functional
>> closure, after which Clojure is presumably named.

> You're missing the point.  A defn inside another defn doesn't do what you
> think it does.  defn always creates a global variable, even when it looks
> like it should create a local.  You can create closures, but you should use
> letfn instead.

Got it, thanks -- a beginner's path through the intro web pages does
not lead one through letfn.

That fact is likely to throw people with background in Scheme more
than it is newbies to LISP-like languages, because the Schemers are
much more likely to be used to using a lexically scoped LISP, and
Clojure's constructs are a mix of lexical and dynamic scoping.

>
> Well if you can't duplicate the bug in a simpler context, it seems more
> likely that the bug is in the logic of your code, or your understanding of
> these constructs, doesn't it?

The invocation of with-local-vars or binding trashes the Clojure
environment when the invocation completes. Possibly it may be just an
application bug. It is also very possibly be that an unusual
combination of legitimately-used mechanisms have brought a bug to the
surface that does not come to the surface when these mechanisms are
used in isolation.

> Your example is long enough I only had time to glance briefly at it.  Based
> on what I could glean from that quick look, I think you may have a
> misunderstanding about how with-local-vars works. vars are thread-specific,
> and they have a lifetime that is delimted by dynamic scoping rather than
> lexical scoping.  Using vars in conjunction with futures seems like a recipe
> for disaster.

The vars collect results of invoking future. If these vars are never
dereferenced, presumably the references would be garbage collected,
regardless of the state of the threads spawned by those invocations.
These results are in fact dereferenced via calls to deref; these deref
calls do not return until the threads have terminated.

I have walked through all of this in Eclipse. The algorithm inside
with-local-vars or binding works as expected. The futures complete
their tasks and deref accomplishes synchronization before the with-
local-vars exits. When it exits, all currently active function
parameters shown by Eclipse revert to values of nill, even though the
function binding those parameters has not completed.

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