Updates mutual recursion example (#983)

so it can be executed without blowing the stack.
This commit is contained in:
Tim Dévé 2020-11-20 14:12:49 +00:00 committed by GitHub
parent 1b87bfbcb9
commit 4f66803ab7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,18 +1,19 @@
(use IO)
; 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))
(register f a)
(defn-do g [i]
(println* "I'm g")
(f (inc i)))
(defn g []
(do
(println "I'm g")
(f)))
(defn f []
(do
(println "I'm f")
(g)))
(defn-do f [i]
(println* "I'm f")
(if (> i 10)
i
(g (inc i))))
(defn main []
(do
(f)
0)) ;; Need a return value to get a concrete type.
(println* (fmt "Final result: %i" (g 0))))