On Mon, Mar 9, 2009 at 9:55 AM, Tuomas J. Lukka <tuomas.lu...@gmail.com> wrote:
>
> You are "holding on to the head". Try replacing "def perms" with "defn
> perms []" and calling it when you start using it. That way the
> permutations are let go as soon as they come. I noticed this with some
> scripts that go through large files: it's really important to create
> lazy longs sequences just for the one use and let them be garbage
> collected right away.

For what it's worth, I wanted to write the permutations function to
create an uncached sequence, so the holding-on-to-the-head problem
would be a non-issue.  There was a period of time where Clojure
offered such a thing (it was called lazy-seq, but different from the
current lazy-seq).  As far as I know, Rich is still on the fence about
whether to put something like that back in, but is waiting to see how
all the new laziness additions play out before making any further
decisions on the matter.

I think the ability to create an uncached sequence would be a great
tool for power-users and library developers, because it would make
functions like permutations faster and make them easier to use for
people who are new to Clojure and new to laziness.  I could roll my
own uncached variant (and actually, I do that on my own machine), but
I'd rather not have the combinatorics library have any dependencies
beyond the core.

So for now, Tuomas' workaround is key.  When giving names to long,
lazy sequences, it is very important to wrap them in a function and
give the name to the function, rather than the sequence itself.

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

Reply via email to