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