E.Ireland@massey.ac.nz (Evan Ireland) (02/21/91)
Hi, The recent discussion on tail-calling and garbage collection reminded me of something I have intended to ask for a while now. How do the Scheme compilers which compile to C (or "similar" languages) handle tail recursion? For example, I imagine that most compilers would generate a "goto" statement in the C function for the following Scheme procedure. (Please pardon any minor syntactic errors). (define alength (lambda (x n) (if (pair? x) (alength (cdr x) (+ n 1)) 0))) But what if I define two mutually tail-recursive procedures? (define even? (lambda (n) (if (= n 0) #t (odd? (- n 1))))) (define odd? (lambda (n) (if (= n 0) #f (even? (- n 1))))) If the compiler generates separate C functions for each of these Scheme procedures, the "goto" statement can no longer be used, and I don't imagine that setjmp/longjmp are any more useful either. I know of one solution to this problem, for applicative languages without call/cc, but I am particularly interested in how the Scheme->C compilers do it. Thanks, ------------------------------------------------------------------------------- E.Ireland@massey.ac.nz Evan Ireland, School of Information Sciences, (063) 69-099 x8541 Massey University, Palmerston North, New Zealand.