Assignments to auxiliary variables inside a second programm call
For example: Have a look on the following LOOP-Code.
def fakultaet
in: x;
out: y;
aux: z, a;
y := 1;
z := x;
a := 1;
loop z do
y := y * x;
x := x - a;
enddo
enddef;
def binomialkoeffizient
in: n, k;
out: r;
aux: fn, fk, nk, fnk, nenner;
fn := fakultaet(n);
fk := fakultaet(k);
nk := n - k;
fnk := fakultaet(nk);
nenner := fk * fnk;
r := fn div nenner;
enddef;
in: n, k;
out: b;
b := binomialkoeffizient(n, k);
If you step through it using the debugger, you will see, that the variable a
inside of the second call to fakultaet
is assigned with 0
after the command a := 1
. If you remove this line and edit the rest equivalently, the code works as expected:
def fakultaet
in: x;
out: y;
aux: z;
y := 1;
z := x;
loop z do
y := y * x;
x := x - 1;
enddo
enddef;
def binomialkoeffizient
in: n, k;
out: r;
aux: fn, fk, nk, fnk, nenner;
fn := fakultaet(n);
fk := fakultaet(k);
nk := n - k;
fnk := fakultaet(nk);
nenner := fk * fnk;
r := fn div nenner;
enddef;
in: n, k;
out: b;
b := binomialkoeffizient(n, k);