Tail recursion (87)

50 Name: #!/usr/bin/anonymous : 2006-03-10 22:54 ID:JgtJdHur

Ugh...

Okay. An iterative loop:

while (x) {

do y;

} (hold memory in z for next iteration)

Now, since you're using a bounded amount of space for z, you can imagine that all the information in z is held in a struct.

Tail recursion:

function tail (input, z) {

if (done) return answer;
else tail (input for next iteration, z for next iteration)
}

When you do the recursive call, all the information required is in the arguments, and you can drop everything else, thus using the same stack area.

This thread has been closed. You cannot post in this thread any longer.