mirror of
https://github.com/carp-lang/Carp.git
synced 2024-09-17 08:27:45 +03:00
Updates mutual recursion example (#983)
so it can be executed without blowing the stack.
This commit is contained in:
parent
1b87bfbcb9
commit
4f66803ab7
@ -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.
|
|
||||||
|
Loading…
Reference in New Issue
Block a user