## Problems with +=, -=, *=, /= and %= in SLUDGE

The above operations should not be performed on elements of a stack which are obtained using square brackets containing an index which is the result of code which may change one or more values (such as a function call or, ++ or --). The reason for this is that any code used to determine the index value will be performed twice. That is to say, this is safe...

    a /= 7;

This is safe...

    someStack[20] += "... or so it would seem.";

This is safe...

    anotherStack[4 * h + 2 - i] %= blah[r ++];

But this isn't.

    strangeResults[someSub ()] *= 2;

The reason for this is that these lines are partially expanded by the compiler before being compiled. The best way to think of this is that the first three examples are treated as...

    a = a / 7;

    someStack[20] = someStack[20] + "... or so it would seem.";

    anotherStack[4 * h + 2 - i] = anotherStack[4 * h + 2 - i] % blah[r ++];

Therefore, the fourth example is treated as...

    strangeResults[someSub ()] = strangeResults[someSub ()] * 2;

As you can see, the index part will be executed more than once. However don't assume your program will be compiled this way... future releases of the SLUDGE compiler may well fix the problem.

### See also:

Variable Operations

The Multi-Purpose Stack / Array / Queue Type

SLUDGE and this SLUDGE documentation are copyright Hungry Software and contributors 2000-2012