Re: Local recursive lazy sequences

2008-09-01 Thread Rich Hickey
On Aug 31, 1:58 pm, Achim Passen <[EMAIL PROTECTED]> wrote: > Hi! > > Is there a way to have locally bound recursive lazy sequences in > Clojure? I'd like to define a function that uses a lazy seq as an > interim result, so i wouldn't want to use a top-level def. > > I'll try to give a short exa

Re: Local recursive lazy sequences

2008-09-01 Thread Achim Passen
Hi Mike, thank you for your reply! On Sep 1, 3:15 pm, "Michael Reid" <[EMAIL PROTECTED]> wrote: > (defn fib [n] >   (let [fibs2 (fn fibs2 [] (lazy-cat '(0 1) (map + (fibs2) (drop 1 > (fibs2)] >     (nth (fibs2) n))) Dodgy. ;-) I wasn't aware of named anonymous fns – nice. But i suspect di

Re: Local recursive lazy sequences

2008-09-01 Thread Michael Reid
Hi Achim, On Sun, Aug 31, 2008 at 1:58 PM, Achim Passen <[EMAIL PROTECTED]> wrote: > Now suppose you want to define a function which returns the nth > fibonacci number, but you down want "fibs" around globally. My guess > was: > >(defn fib [n] > (let [fibs2 (lazy-cat '(0 1) (map

Local recursive lazy sequences

2008-09-01 Thread Achim Passen
Hi! Is there a way to have locally bound recursive lazy sequences in Clojure? I'd like to define a function that uses a lazy seq as an interim result, so i wouldn't want to use a top-level def. I'll try to give a short example. You can define the sequence of fibonacci numbers lazily-recurs