Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The "spaghetti code" conversion - using labels instead of calls - only works if the original recursion didn't actually need to be recursive, i.e. it didn't require storage proportional to its maximum stack depth, and could already have been rewritten as a loop.

Other than that, the approach trades code (time) for data (space). Instead of making a copy of activation record variables at each level of the recursion, the mutation of the activation record variables is implicitly encoded in the return address pushed onto the call stack, because the code at the return address undoes the mutation.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: