April 22, 2012
Reference Counting and Tail Calls
One thing I thought about today is reference counting in combination with tail calls. Imagine a function like this:
function f(x) { return g(x+1); } Now consider that x is a reference counted object and that x + 1 creates a new object. The call to g(x + 1) shall be in tail call position.
In most reference counted languages, the reference to an argument is owned by the caller. That is, f() owns the reference to x + 1. In that case, the call to g() would no longer be in a tail call position, as we still have to decrease the reference count after g() exits.
...
Read more 》