Re: Example of use of Atom: Fibonacci generator

2009-02-16 Thread timc
Thanks for these interesting replies - I have some way to go in my understanding of the power of functional programming. I look forward to seeing Stuart's chapter 5! On Feb 16, 11:25 am, Timothy Pratley wrote: > Also consider (fromhttp://en.wikibooks.org/wiki/Clojure_Programming/Examples): > > (

Re: Example of use of Atom: Fibonacci generator

2009-02-16 Thread Timothy Pratley
Also consider (from http://en.wikibooks.org/wiki/Clojure_Programming/Examples): (defn fib-seq [] ((fn rfib [a b] (lazy-cons a (rfib b (+ a b 0 1)) user> (take 20 (fib-seq)) (0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181) Regards, Tim. --~--~-~--~--

Re: Example of use of Atom: Fibonacci generator

2009-02-15 Thread Michel Salim
On Feb 15, 2:44 pm, timc wrote: > I'm new to Clojure, just thought I would share this. > I was playing around, trying to understand Atoms and I devised a > function that generates the next value in the Fibonacci sequence each > time it is called. > > (def fib-gen-val (atom [1 1])) > > (defn fib