Title: Pointer function references as lhs in assignment Submitted by: Aleksandar Donev Status: For Consideration References: Interp 000074 Basic Functionality: Allow references to functions returning an associated pointer to appear as the lhs of assignment statement, where the value of the target is changed. This is parallel to the way we treat regular pointers. Example: FUNCTION storage(key) RESULT(loc) INTEGER, INTENT(IN) :: key REAL, POINTER :: loc loc=>... END FUNCTION ! Make the following legal storage(5)=0.5 Rationale: The proposed change makes the language more symmetrical. It arose while looking at an interpretation request, number 000074, titled "TARGET dummy arguments and POINTER expressions". The proposed change also brings in a very useful functionality: It allows one to change between different data-structures with little to no change in the source code. Consider an example of a dictionary data-structure, where the keys are INTEGER and the data values are REAL. A simple implementation might use an array to store the values: TYPE :: Dictionary_t REAL, DIMENSION(:), ALLOCATABLE :: storage ... END TYPE Later however, a more sophisticated data-structure (say a hash-table) that conserves memory may be implemented, substituting the array with a pointer-valued function which returns a pointer to the storage location corresponding to the key: TYPE :: Dictionary_t REAL, DIMENSION(:), ALLOCATABLE :: storage CONTAINS PROCEDURE :: storage ! See previous function END TYPE FUNCTION storage(dictionary, key) RESULT(loc) CLASS(Dictionary_t), INTENT(INOUT) :: dictionary INTEGER, INTENT(IN) :: key REAL, POINTER :: loc loc =>... END FUNCTION The text of the code will need minor changes: TYPE(Dictionary_t) :: dictionary ... dictionary%storage(5)=0.5 Another example in numerical problems includes switching from full to sparse storage for a matrix without having to change all the references. Estimated Impact: The proposed change requires introducing new syntax rules, however, it is simple in nature and so we should easily get it right. The cost to implementations will be low. Detailed Specification: Add a second form of in 7.4.1.1 in R734: is = is or where is a and is a pointer History: Comments: Malcolm Cohen, Nihon NAG, Tokyo: (1) I have been sent two related Fortran 2003+ suggestions, which I would like the U.K. panel to consider. They are both from Aleksandar Donev. The second one (pointer_lhs) I have yet to form a definite opinion on, except that I think we should consider it. P.S. If we do decide to put them forward I think the text and examples need a little work. I'm willing to help with that. John Reid, JKR Associates, Oxford: I will advocate that we go for both of these. It seems to me to be illogical to go for one and not the other. Malcolm Cohen, Nihon NAG, Tokyo: (2) I don't like "pointer lhs" so much, but I don't really object.