[I7] Arithmatic... wait, this can't be right?

Inform 7, of course, knows about the priority of mathematical symbols. It evaluates “6 - 4 / 2” correctly as 6 - (4 / 2) = 4, not as (6 - 4) / 2 = 1.

Well… sometimes.

[code]“Say it with words” by Victor Gijsbers

Mathematical laboratory is a room.

When play begins:
let n be 6 - 4 / 2;
say “Obviously, 6 minus 4 divided by 2 is [n].”;
let m be 6 minus 4 divided by 2;
say “Unless, of course, it is [m].”[/code]
This leads to the unexpected:

Note that the manual (section 14.2) tells us that “the verbal and symbolic forms of these phrases are equivalent”. Do I miss something obvious, or is this a big fat evil bug?

Well, this is the relevant chunk of code from the standard rules.

The different forms are indeed defined in identical ways. Looks like BODMAS hasn’t yet been defined for wordy variations. I blame quantum mechanics. :laughing:

It’s easily fixed with brackets, though.

Sure, it’s easily fixed, but this is a likely source of very hard to detect bugs… I just noticed it for one of my calculations, but had not been noticing it for several others that used the same format.

Very true! I’ve learnt this the hard way, resulting in my using of brackets pretty much all the time.

It’s appears to be a compiler glitch when going from I7 to I6. Upon checking the I6 code generated, it seems that:

6 - 4 / 2

is translated to

6- (IntegerDivide(4,2))


6 minus 4 divided by 2

is translated to

IntegerDivide( (6-4) ,2)

which give very different results!

Yes, that’s a bug, and a rather odd one. Of the forms:

let K be 6 minus 4 divided by 2;
let M be 6 - 4 divided by 2;
let N be 6 minus 4 / 2;
let P be 6 - 4 / 2;

…only the last gets correct associativity. Since, as you note, the operations are defined identically, there must be something weird going on with I7’s own parsing.

Another thing to notice is that

"IntegerDivide( (6-4) ,2)" (for "6 minus 4 divided by 2", "6 - 4 divided by 2" and "6 minus 4 / 2") 


"6- (IntegerDivide(4,2))" (for "6 - 4 / 2")

both have an extra pair of brackets. This means that not only is it getting the order wrong, it is actively doing so.

This should probably be reported.

I have reported it: inform7.com/mantis/view.php?id=1005