Ben <berndhe...@gmx.de> writes:

> (defn whole-numbers [] (iterate inc 1))
>
> If I use it like this at the REPL
>
> (take 99999999 (whole-numbers))
>
> I get:
> Java heap space [Thrown class java.lang.OutOfMemoryError]
>
> This unexpectedly is the same result that I expectedly get when
> binding whole-numbers to a top-level var and use a huge portion of
> that. Since whole-numbers is lazy I expected it to run for a certain
> amount of time but never to run out of memory. Has this anything to do
> with using the function at the REPL or is there another reason for
> that?

Yes, it's because of the REPL.  For convenience the REPL holds onto the
last 3 values as *1 *2 and *3.  Thus there is a reference to the head of
the sequence preventing it from being garbage collected.

Try (println (take 99999999 (whole-numbers))) instead.

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