On Thu, Jan 1, 2009 at 6:40 PM, Christian Vest Hansen <karmazi...@gmail.com> wrote: > > On Thu, Jan 1, 2009 at 11:48 PM, Chouser <chou...@gmail.com> wrote: >> >> On Thu, Jan 1, 2009 at 2:47 PM, Rock <rocco.ro...@gmail.com> wrote: >>> >>> Given that there's nothing like letrec in Clojure, and that let acts >>> like let* in CL, I gather that local recursive functions are possible >>> whereas local mutually recursive ones are not. Is that correct? If so, >>> will they ever be in the future? >> >> I assume you meant "are not possible". I think someone previously >> posted a letrec macro using something he called a "Y* combinator". I >> don't know what that is, but he said it was slow. >> >> Here's another way. Nothing about it is pretty, but it is a >> possibility: >> >> (let [my-even-atom (atom nil) >> my-even? (fn [i] (@my-even-atom i)) >> my-odd? (fn [i] >> (if (zero? i) >> false >> (@my-even-atom (dec i))))] >> (swap! my-even-atom >> (constantly (fn [i] >> (if (zero? i) >> true >> (my-odd? (dec i)))))) >> (my-odd? 4)) > > I don't get this listing. You define my-even? but do not use it?
Good point. I included a convenience function and forgot to use it. Replace the second "@my-even-atom" with "my-even?": (let [my-even-atom (atom nil) my-even? (fn [i] (@my-even-atom i)) my-odd? (fn [i] (if (zero? i) false (my-even? (dec i))))] (swap! my-even-atom (constantly (fn [i] (if (zero? i) true (my-odd? (dec i)))))) (my-odd? 4)) --Chouser --~--~---------~--~----~------------~-------~--~----~ 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 clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---