I’d be grateful for comments on my understanding the standard definitions regarding substrings and array sections.
We have following defs in the F2018 standard:
R908 substring is parent-string ( substring-range )
R909 parent-string
is scalar-variable-name
or array-element
[…]
9.5.3 Array elements and array sections
9.5.3.1 Syntax
R917 array-element is data-ref
C924 (R917) Every part-ref shall have rank zero and the last part-ref shall contain a subscript-list.
R918 array-section is data-ref [ ( substring-range ) ]
Am I right to deduce that in
program sc
character(4) :: stab(5) = (/'abcd','efgh','ijkl','mnop','qrst'/)
print *, stab(2)(1:1)
! is a substring of an array element (outputs 'e')
print *, stab(1:3)(2:3)
! is an array section using a substring-range syntax (outputs 'bcfgjk')
end program sc
I got confused because at first I thought stab(1:3)(2:3) should be a substring, but then I realized that the preceding parent-stringstab(1:3) is not an array element.
I think that stab(1:3)(2:3) would be considered an array-section of substrings, but I think a follow up question would be, do you have a reason it matters exactly what it’s called? Most of the time it’s just useful to know that it’s legal, but the exact name is not so important.
Array-section of substrings is something quite different from a substring of an array-section. The latter could, in principle, be interpreted as (taking the above example as a base) (stab(1)//stab(2)//stab(3))(2:3)symbolically, of course, taking a substring of an expression is invalid.
Consider following snippet which illustrates the idea.
So, my reason is that if a student asks what is the difference and why array-section is not valid parent-string of a substring, I need a clear and firmly standard-based answer: stab(1:3)(2:3)is not a substring, no matter how similar to a substring it looks.