On Tue, Dec 9, 2008 at 2:28 PM, Stephan Mühlstrasser < [EMAIL PROTECTED]> wrote:
> > 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. > > > Ok, I'm confused here. Why does wrapping his logic into a function alleviate this problem? Can you give a more detailed explanation, I'd like to understand what's going on here. - Drew > > > 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 clojure@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---