J3/13-223 To: J3 From: Van Snyder Subject: Conditional variables Date: 2013 December 20 Reference: 04-192, 13-221, 13-222 Title: Conditional variables Submitted by: Van Snyder Status: For consideration Basic functionality: Define syntax to select a variable, depending upon conditions. Rationale: Reduces the number of statements, and thereby long-term cost. There is no way, within a single expression, to select one variable from a set, other than to give them all the target attribute and invoke a function that returns a pointer associated with one of them. A different function is required for every type, kind, rank, and number of variables in the set from which a selection is to be drawn. This does not work within specification expressions if any of the variables are optional dummy arguments. 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 a is referenced or defined, 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, expressions within the corresponding are evaluated, it becomes the variable, no further s are evaluated, and no expressions within or any other are evaluated. If no is true, expressions within are evaluated, its becomes the value of the variable, and no expression within a 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 variable 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 selected. Draft edits: To estimate scope of project Add an alternative to R602 <> Add syntax rules R602a <> .IF. .THEN. [ .ELSEIF. .THEN. ]... .ELSE. .ENDIF. R602b <> R602c <> Add a constraint C602a (R702a) and all s shall have the same declared type, kind type parameter values, and rank. Insert paragraphs 6.2p3 etc after C607 (maybe introduce subclauses 6.2.1 General and 6.2.2 Conditional variables): "Where a is referenced or defined, 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, expressions within the corresponding are evaluated, it becomes the variable as if it were not conditional, no further s are evaluated, and no expressions within or any other are evaluated. If no is true, expressions within are evaluated, it becomes the variable as if it were not conditional, and no expression within a is evaluated. The declared type and kind type parameter values of a conditional variable 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 selected."