Hello John On 27-Nov-99, you wrote: >>> If I've comprehended that correctly, a good language should >>> eliminate tail >>> recursion and replace it by iteration. This is a feature of most >>> CommonLISP systems and Scheme. > >> Well, that would probably require some static analysis of the >> REBOL program, something which is probably not part of the >> philosophy of the REBOL interpreter. (Am I mistaken?) > > You don't need to do static analysis, you just have to notice > that the current function is calling another function, and that > the result of that call is only going to be returned, i.e., you > are making a function call followed immediately by a return. > If you replace the CALL/RET pair with a JMP, and adjust the stack, > you should be all set. That's definitely what I would consider static analysis. Additionally, remember that in REBOL you can define 'return to do so much else than simply return a value (in fact, 'return is just a value like everything else, and thus can be redefined), so you will never know what the value of 'return will be just after returning from a function call. Though you should be able to remove tail recursion in the specific example of return some-function arg1 arg2 ... argn But using 'return isn't the only means of returning a value. Consider this (untested, though): fac1: func [n] [ either (n > 1) [return n * fac1 n - 1] [return 1] ] fac2: func [n] [ either (n > 1) [n * fac2 n - 1] [1] ] fac1 and fac2 are semantically identical. But how would you dynamically see that you should eliminate tail recursion in fac2? Sure, you could do it by looking forward some bytes (seeing that there isn't anything more to do in the body of the function), but if you should do this properly, program execution will probably be slowed down. Regards Ole
