[I6] Evaluation rules for logical not (~~) operator?

I spent a while debugging a strange problem in some code, and I discovered that the condition

(~~(true == true) || (true == true))

evaluates to FALSE (which occurs even in Inform 6.35). DM4 Table 1B (p. 518, https://inform-fiction.org/manual/html/tables.html#tbl1a) indicates that operators ~~ and || have the same precedence. The explanatory note at the bottom of the table indicates (along with a similar one on p. 20 or https://inform-fiction.org/manual/html/s1.html#s1_3) that both && and || (which have the same precedence as ~~) are evaluated left to right. (The operator ~~ is not explicitly mentioned in either case.)

Unless I’m misunderstanding, it does not appear that the ~~ operator is evaluated left to right in the condition above, which per left to right evaluation would be processed:

(~~true || true) [parentheses first]
(false || true)  [left to right, first step]
(true)           [left to right, second step]

Am I misunderstanding something here? If not, what are the actual rules around the order of evaluation for the ~~ operator? (For now, I’m trying to train myself to prefer the ~= operator when applicable.)

Thank you, @auraes – I missed that one. (From just last week, too!) More notes for my marked-up DM4…

1 Like