Two functions which call each other recursively
Is it possible to define two functions in clojure which recursively call
each other? For example, this pair:
(defn a [x]
(if (= 0 x) 0 (b (dec x))))
(defn b [x]
(if (= 0 x) 0 (a (dec x))))
Compilation fails with:
Unable to resolve symbol: b in this context
Since I haven't defined b when I try to call it in a.
e.g., in ruby this works fine:
def a(x)
x == 0 ? x : b(x-1)
end
def b(x)
x == 0 ? x : a(x-1)
end
No comments:
Post a Comment