Carp/examples/mutual_recursion.carp
Tim Dévé 4f66803ab7
Updates mutual recursion example (#983)
so it can be executed without blowing the stack.
2020-11-20 15:12:49 +01:00

20 lines
452 B
Plaintext

; This is dangerous because you've now told the Carp compiler that `f`
; _will_ exist. So you won't get a compile error from Carp if you don't
; implement it or change the signature. You should get a error in the C
; compiler though.
(register f (Fn [Int] Int))
(defn-do g [i]
(println* "I'm g")
(f (inc i)))
(defn-do f [i]
(println* "I'm f")
(if (> i 10)
i
(g (inc i))))
(defn main []
(println* (fmt "Final result: %i" (g 0))))