Re: How can I STOP a cursed recursion?
- Posted by Ricardo M. Forno <rmforno at tutopia.com> Jun 22, 2006
- 604 views
don cole wrote: > > Hello everybody, > > My computer has been broken for about a week. I guess nobody missed me. > I've been catching up on my Euforum reading. I've seen a lot of talk about > the code, > > procedure Help() > help() > end procedure > > If this code is not illegal it should be. How can you call a procedure from > within this procedure? I find this code very disturbing as it goes against all > the rules. One should be able to call help() from any number of places besides > help it self. And lastly I don't see any point of doing that way. > > Don Cole Hi, Don. Recursion is not only an elegant form of programming some tasks, but sometimes it is badly needed. It can be shown that what you do by means of recursion can be done in another way, but sometimes things may become very difficult in this "other way". The typical example is (code not tested): (a should be an integer, but the result may be too large to fit into an integer) function factorial(atom a) if a = 0 then return 1 end if return a * factorial(a - 1) end function This can be done without recursion: function factorial(atom a) atom r r = 1 for i = 2 to a do r = r * i end for return r end function This is a bit longer than the recursive version, but this does not show the real benefits of recursion. You will find more useful examples of recursion in my General Functions contributed program, or in my recently updated General Sudoku program. In this last program, it will be difficult to process an undefined number of dimensions without using recursion. Regards.