To: J3 J3/18-152 From: Dan Nagle Subject: short-circuiting logical operators Date: 2018-February-15 Introduction ------------ Logical operators for .and. and .or. that do not evaluate their right operand unless the left operand value requires right operand value to compute the value of the expression, have been requested previously but never made the cut. Perhaps now is the right time to reconsider them. Specifically, a logical expression such as i <= n .and. a(i) > 0.0 where n is the upper bound of a, appears frequently in codes. But there is no guarantee that a(i) will be fetched only after i is known to be in bounds. The obvious repair, of nesting the second condition, is unpopular, at least among some applications programmers. Even when no use is made of a(i) beyond evaluating its (undefined) value in the expression, it may trigger a bounds warning. Being in-bounds, of course, is exactly why the i <= n appears to the left. Thus, an .andthen. operator that makes such a guarantee would be useful. By analogy, an .orelse. operator that makes the same guarantee regarding the right operand would also be desirable. Feature ------- Standardize logical operators .andthen. and .orelse. .andthen. has the same truth table as .and. but guarantees that its right operand is not evaluated when the left operand is false (and thus the expression value is known to be false without the right operand value). .orelse. has the same truth table as .or. but guarantees that its right operand is not evaluated when the left operand is true (and thus the expression value is known to be true without the right operand value). They should have the lowest precedence, after user-defined binary operators.