I7: Is this the New Math?

So, I can’t help noticing that arithmetic works differently in Inform-land:

[code]Home is a room.

To decide what number is X:
decide on 10 - 5 - 2.

To decide what number is Y:
decide on 10 - 5 * 2.

To decide what number is Z:
decide on 10 * 5 - 2.

When play begins:
say “10 - 5 - 2 = [X].”;
say “10 - 5 * 2 = [Y].”;
say “10 * 5 - 2 = [Z].”[/code]

This yields 7, 10, and 30, rather than the more conventional 3, 0, and 48. Inform is executing math right to left, of all things, and ignoring orders of operations.

But wait–there’s more. If you phrase things in terms of defining equations, suddenly arithmetic works properly again. Which means that, depending on how you code it, the same formula may yield different answers:

[code]Home is a room.

To decide what number is X:
decide on 10 - 5 - 2.

To decide what number is Y:
decide on 10 - 5 * 2.

To decide what number is Z:
decide on 10 * 5 - 2.

When play begins:
say “10 - 5 - 2 = [X].”;
say “10 - 5 * 2 = [Y].”;
say “10 * 5 - 2 = [Z].”;
let n be given by n = a-b-c where n is a number, a is 10, b is 5, c is 2;
let m be given by m = e-fg where m is a number, e is 10, f is 5, and g is 2;
let o be given by o = hi-j where o is a number, h is 10, i is 5, and j is 2;
say “10 - 5 - 2 = [n].”;
say “10 - 5 * 2 = [m].”;
say “10 * 5 - 2 = [o].”[/code]

I haven’t found anything in the documentation about this (14.13 states that equations parse according to the normal rules of algebra, but it doesn’t mention that ordinary mathematical operations don’t). Why? Just why?

Is that a rhetorical question?

Yeah, I use parenthesis for every math operation (for myself, if not for Inform). A few nasty surprises early on convinced me this was a good idea.

It’s a known issue. See bug #776.