Re:How Tail Call Optimization Works
by eyelidlessness on Friday January 08, 2021 @02:26AM
(#25682446)
Maybe it’s more of me showing my naivety but I still think of a recursive function call as bindings and computation. My mental model is f(x) -> f(y(x)) = f(x) -> g(x), where g is a function wrapping the body of f. It’s surely not what the compiler does, but it makes thinking about recursion no more complicated than thinking about any old function. Then the only thing I need to think about beyond that is “does my environment support TCO, or am I certain my data fits in the call stack?”
[ Parent
| on HN ]
Consider that some processors were too small to fit a stack. Some languages (notably BASIC), only had what you might call 'static' variables (to use the C name), so when you recursed into them, the variables would be shared across all calls to that function.
Re:How Tail Call Optimization Works
by eyelidlessness on Friday January 08, 2021 @02:45AM
(#25682548)
And that’s a good case for supporting recursion but eliminating branching! You can goto and rebind to your heart’s content as long as you don’t have to back out of a condition