I tried this:
(declare F)
(defn M [n]
(if (zero? n)
0
(- n (F (M (dec n))))))
(defn F [n]
(if (zero? n)
1
(- n (M (F (dec n))))))
and for large n I got the expected stack overflow. Then I tried to
trampoline the functions:
(declare F)
(defn M [n]
(if (zero? n)
0
#(- n (F (M (dec n))))))
(defn F [n]
(if (zero? n)
1
#(- n (M (F (dec n))))))
Now (trampoline #(M 7)) yields
java.lang.ClassCastException: user$M__760$fn__762 cannot be cast to
java.lang.Number (NO_SOURCE_FILE:0)
Does anybody have an idea to get this to work?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
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
-~----------~----~----~----~------~----~------~--~---