When writing nested functions in Octave, the variables do not seem to be encapsuled:
function r = asd()
fn1();
endfunction
function res1 = fn1()
res1 = 0;
function res2 = fn2()
res2 = 0;
for i = 10:20
res2 = res2 + i;
endfor
endfunction
for i = 1:10
printf("i before calling fn2(): %d\n", i);
res1 = res1 + fn2();
printf("i after calling fn2(): %d\n", i);
endfor
endfunction
This seems very odd to me because it screams for bugs, right? Is there a specific reason the variables are not encapsuled here?