You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If we create closures inside a function we transform, then the enclosing environment sees the modified local variables in the loop. This breaks the illusion that we have recursive calls.
we have two closures, the named call_right and the anonymous function(right_sum) ... inside it. These will capture the environment of the sum_leaves function that contains cont. If we transform the function, however, they will have access to an updated left, right and cont and nothing good will come of that.
We can fix it by capturing cont explicitly in a closure or a thunk. In the code below, I use closures.
If we create closures inside a function we transform, then the enclosing environment sees the modified local variables in the loop. This breaks the illusion that we have recursive calls.
With a function like this:
we have two closures, the named
call_right
and the anonymousfunction(right_sum) ...
inside it. These will capture the environment of thesum_leaves
function that containscont
. If we transform the function, however, they will have access to an updatedleft
,right
andcont
and nothing good will come of that.We can fix it by capturing
cont
explicitly in a closure or a thunk. In the code below, I use closures.With a bit of static analysis, we should be able to automatically extract closures and capture the right environment.
The text was updated successfully, but these errors were encountered: