On Wed, Jul 29, 2009 at 9:49 AM, John Harrop <[email protected]> wrote:
> On Wed, Jul 29, 2009 at 2:59 AM, Daniel Lyons <[email protected]>wrote: > >> Probably it would help to try and implement a lazy >> list of the Fibonacci sequence before looking at that code, and then >> maybe try some other mathematical sequences that are a little easier >> to construct too. >> > > Using the super-lazy-seq macro Wrexsoul posted a month or so ago, that's > dead easy: > > (super-lazy-seq [a 0 b 1] (next-item b b (+ a b))) > Or, using rec-seq/rec-cat from seq-utils: (rec-cat fibs [1 1] (map + fibs (rest fibs))) http://github.com/richhickey/clojure-contrib/blob/e20e8effe977640592b1f285d6c666492d74df00/src/clojure/contrib/seq_utils.clj#L97 > On the other hand, > > (defn fibs [] (cons 1 (cons 1 (lazy-seq (map + (fibs) (rest (fibs))))))) > (def fibs (memoize fibs)) > That's roughly what rec-seq does but using an atom and a local instead of a var to keep the mutable state local. Christophe -- Professional: http://cgrand.net/ (fr) On Clojure: http://clj-me.blogspot.com/ (en) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] Note that posts from new members are moderated - please be patient with your first post. 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 -~----------~----~----~----~------~----~------~--~---
