J3/99-196r2 Date: 06 August 1999 To: J3 From: Malcolm Cohen Subject: Baroque spelling of 'WITH' functionality This is a re-issue of 99-171 with the typographical errors corrected and the edits revised to apply to 99-007r2. 1. Introduction The editor has called to our attention that people who are not using extensible types will not think of looking in SELECT TYPE to find the ASSOCIATE facility. The syntax is also weird and inconvenient - "SELECT TYPE" and "TYPE DEFAULT are misleading. Therefore we propose that a separate (but very similar) construct should be used for accessing the ASSOCIATE facility when type-selection is not required. 2. Syntax ASSOCIATE ( => [ , => ]... ) ... END ASSOCIATE Each is a construct entity that has the scope of the ASSOCIATE block, just like the in a SELECT TYPE. For consistency, we should change our existing SELECT TYPE ( ) [ ASSOCIATE( ) ] to SELECT TYPE ( [ => ] ) 3. Examples Before these changes, an example might look like this: TYPE(MYTYPE) AX,AY ... SELECT TYPE ( AX%B(I,J)%D ) ASSOCIATE ( ZX ) TYPE DEFAULT SELECT TYPE ( AY%B(I,J)%D ) ASSOCIATE ( ZY ) TYPE DEFAULT W = ZX*X + ZY*Y END SELECT END SELECT After these changes, it would look like this: TYPE(MYTYPE) AX,AY ... ASSOCIATE ( ZX => AX%B(I,J)%D, ZY => AY%B(I,J)%D ) W = ZX*X + ZY*Y END ASSOCIATE 4. Discussion Given this construct, it no longer makes sense to allow SELECT TYPE on non- polymorphic expressions; therefore we limit SELECT TYPE to polymorphic exprs. 5. Edits {Add the ASSOCIATE construct to the list of executable constructs} [11:2+] Add new line "<> ". {Allow the blank between END and ASSOCIATE to be omitted} [27:33+] Add new line "END ASSOCIATE". {Change SELECT TYPE syntax to be consistent with new ASSOCIATE} [172:24-25] Change "( ) [ ASSOCIATE ( ) ]" To "( [ => ] )". {Require the SELECT TYPE type-selector to be polymorphic.} [172:30+] Add new constraint "Constraint: shall be polymorphic." {Since we only allow polymorphic expressions in SELECT TYPE, TYPE IS should require an extensible type name. This also fixes the problem.} [172:31] Change "" to "" {SELECT TYPE type-selector is polymorphic, so the associate-name in the TYPE DEFAULT block is polymorphic} [173:31] After "name" insert "is polymorphic and" [173:32-33] Delete "; it is ... polymorphic" {Delete old example} [174:37-43] Delete. {Add new syntax} [174:43+] Insert new section and renumber existing 8.1.5 "8.1.5 ASSOCIATE construct The ASSOCIATE construct associates a name with an expression during the execution of its block. 8.1.5.1 Form of the ASSOCIATE construct R820a <> R820b <> [ : ] & ASSOCIATE ( & [ , ]... ) R820c <> => Constraint: If is not a or is a that has a vector subscript, shall not appear in a variable definition context (14.7.7). R820d <> <> R820e <> END ASSOCIATE [ ] Constraint: If the of an specifies an , the corresponding shall specify the same . If the of an does not specify an , the corresponding shall not specify an . 8.1.5.2 Execution of the ASSOCIATE construct Execution of an ASSOCIATE construct causes execution of its block. During execution of that block each associate name is associated (14.6.1.4) with the corresponding selector. The associate name assumes the type, type parameters, rank, and bounds of the selector. The associate name is polymorphic if and only if the selector is polymorphic. If the selector is allocatable it shall be currently allocated; the associate name does not have the ALLOCATABLE attribute. If the selector is a pointer it shall be associated; the associate name is associated with the target of the pointer and does not have the POINTER attribute. J3 note: The interaction between ASYNCHRONOUS or VOLATILE and the ASSOCIATE or SELECT TYPE construct needs to be described. If a selector is a other than an array section having a vector subscript, the associate name is associated with that data object and is definable if and only if the is definable. Otherwise the associate name has the value of the selector, which is evaluated prior to execution of the block, and is not definable. Note 8.13x The association between the associate name and a data object is established prior to execution of the block and is not affected by subsequent changes to variables that were used in subscripts or substring ranges in the . It is permissible to branch to an END ASSOCIATE statement only from within the ASSOCIATE construct. 8.1.5.3 Examples of the ASSOCIATE construct Note 8.14 The following example illustrates an association with an expression. ASSOCIATE ( Z => EXP(-(X**2+Y**2)) * COS(THETA) ) PRINT *, A+Z, A-Z END ASSOCIATE Note 8.15 The following example illustrates an association with a derived-type variable. ASSOCIATE ( XC => AX%B(I,J)%C ) XC%DV = XC%DV + PRODUCT(XC%EV(1:N)) END ASSOCIATE Note 8.16 The following example illustrates association with an array section. ASSOCIATE ( ARRAY => AX%B(I,:)%C ) ARRAY(N)%EV = ARRAY(N-1)%EV END ASSOCIATE Note 8.17 The following example illustrates multiple associations. ASSOCIATE ( W => RESULT(I,J)%W, ZX => AX%B(I,J)%D, ZY => AY%B(I,J)%D ) W = ZX*X + ZY*Y END ASSOCIATE ". {Add associate-name information to 14.1.3 "Statement and construct entities"} [368:30+] Insert "The associate name of an ASSOCIATE construct has a scope of the construct. It has the declared type, dynamic type, type parameters, rank and bounds specified in 8.1.5.2." {Explain hiding of any outer name.} [368:31-32] After "SELECT TYPE" insert "or ASSOCIATE" twice. {Add association information to ch14} [371:47+] Insert "Execution of an ASSOCIATE statement establishes an association between each selector and the corresponding associate name of the ASSOCIATE construct. If the selector is a variable other than an array section having a vector subscript, the association is to the data object specified by the selector; otherwise, the association is to the value of the selector expression. The associate name remains associated to its selector throughout the execution of the construct. Within the ASSOCIATE construct, each selector is known by and may be accessed by its associate name. Upon termination of the ASSOCIATE construct, the association is terminated.".