[Inform 6] Does Inform 6 always have lazy evaluation?

Is this kind of code guaranteed to be safe in Inform 6?

test = (i > 0) && ((100 / i) < 5); ! Could cause division by zero?

if(obj provides my_individual_prop && obj.my_individual_prop > 10) rtrue; ! Could cause attemp to read prop which object doesn’t provide?

1 Like

You’re asking whether the logical operators && and || short-circuit the way they do in most other languages?

Yes, they do. The I6 manual mentions this in a note in chapter 1:

&& and || work left to right and stop evaluating conditions as soon as the final outcome is known. So for instance if (A && B) ... will work out A first. If this is false , there’s no need to work out B .

4 Likes

when not recursively number-crunching (I often code the very first computer problem, that is, ballistic integration…), I apply a pinch of epislon to the divisor, but because the Z-machine, having only signed 16 bit integer, has a too big epislon (1), so I guess isn’t the answer for this issue.

Best regards from Italy,
dott. Piergiorgio.