On Dec 9, 12:34 am, "harrison clarke" <[EMAIL PROTECTED]> wrote:
> you're keeping the head of the sequence, and thus all the elements between
> the head and nth.
>
> it's because you're using def, basically.
>
> if you make a function to return the sequence, and pass the result directly
> to nth, without let-binding it or anything, it should work.
Ok, I got it:
user=> (defn triangle-numbers
[]
(let [rest-fn
(fn rest-fn [current cumulated]
(let [next (+ current cumulated)]
(lazy-cons next (rest-fn (inc current) next))))]
(rest-fn 1 0)))
#'user/triangle-numbers
user=> (nth (triangle-numbers) 1000000)
500001500001
user=> (nth (triangle-numbers) 10000000)
50000015000001
Thanks!
Stephan
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---