J3/13-222 To: J3 From: Van Snyder Subject: Conditional primaries Date: 2013 December 20 Reference: 04-192, 13-221, 13-223 Title: Conditional primaries Submitted by: Van Snyder Status: For consideration Basic functionality: Define syntax to evaluate part of an expression depending upon conditions. Rationale: Reduces the number of statements, and thereby long-term cost. There is no way, within a single expression, to avoid evaluating a subexpression that is undefined, but that can be determined to be undefined by evaluation of a scalar logical expression. An obstacle that prevents using specification functions for this purpose in declarations is that although specification functions can have optional arguments, a primary in a specification expression (and therefore an actual argument to a specification function reference in a specification expression) cannot be a dummy argument that has the OPTIONAL attribute. An intrinsic generic solution would be helpful. Estimated impact: Minor Markham M6 conformance: Remove simple deficiency. Although nearly trivial, it is a new feature. Detailed specification: Define a syntax term. Proposed spelling: <> .IF. .THEN. [ .ELSEIF. .THEN. ]... .ELSE. .ENDIF. When is , the s are evaluated in the order they appear until one is found to be true, or all have been evaluated. When a is found to be true, the corresponding is evaluated, its value becomes the value of the primary, no further s are evaluated, and neither nor any other is evaluated. If no is true, is evaluated, its value becomes the value of the primary, and no is evaluated. The s and shall have the same declared type, kind type parameter values, and rank. The type and kind type parameter values of the conditional primary are those of the s and . The pointer association status if any, allocation status if any, dynamic type, shape, and length type parameters of the result are those of the or that is evaluated. Draft edits: To estimate scope of project Add an alternative to R701 <> Add syntax rules R701a <> .IF. .THEN. [ .ELSEIF. .THEN. ]... .ELSE. .ENDIF. R701b <> R701c <> Add a constraint C701a (R701a) and all s shall have the same declared type, kind type parameter values, and rank. Replace "It" in 7.1.7p1: "When is , the s are evaluated in the order they appear until one is found to be true, or all have been evaluated. When a is true, the corresponding is evaluated, its value becomes the value of the primary, no further s are evaluated, and neither nor any other is evaluated. If no is true, is evaluated, its value becomes the value of the primary, and no is evaluated. Otherwise it". In 7.1.9.2p1 at [12-007:148:25] insert ", conditional primary" before ", or parenthesized expression". After 7.1.9.2p1 insert a paragraph "If a primary is a conditional primary, its declared type and kind type parameter values are those of the s and , and the pointer association status if any, allocation status if any, dynamic type, shape, and length type parameter values of the result are those of the or that is evaluated." Replace item (2) in the list in 7.1.11p2 with "(2) an object designator with a base object that is a dummy argument that does not have the INTENT(OUT) attribute," { Removing the prohibition against OPTIONAL allows forms such as .if. present(a) .then. size(a,1) .else. 0 .endif. within specification expressions. }