On Sat, Feb 28, 2009 at 7:38 PM, Rich Hickey <[email protected]> wrote:
>
> I've added letfn, which lets you define mutually recursive local
> functions a la CL's labels.
>
> (defn ring [n]
> (letfn [(a [n] (if (zero? n) n (b (dec n))))
> (b [n] (if (zero? n) n (c (dec n))))
> (c [n] (if (zero? n) n (a (dec n))))]
> (c n)))
>
> (ring 1000)
>
> Note this is still subject to stack limits, i.e. no TCO, so please
> don't report your StackOverflowErrors. Useful for bounded data only.
This does work quite nicely with trampoline, though:
(letfn [(a [n] #(if (zero? n) n (b (dec n))))
(b [n] #(if (zero? n) n (c (dec n))))
(c [n] #(if (zero? n) n (a (dec n))))]
(trampoline c 100000))
--Chouser
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---