On Thu, Jan 1, 2009 at 2:47 PM, Rock <[email protected]> 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))
Ick. But perhaps a macro could make style less terrible to use?
--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
-~----------~----~----~----~------~----~------~--~---