Consider the following function
ELEMENTAL FUNCTION int2str(i) RESULT(s)
INTEGER, INTENT(IN) :: i
CHARACTER(LEN = 50) :: appo
CHARACTER(LEN = :), ALLOCATABLE :: s
WRITE(appo, '(I0)') i
ALLOCATE(s, source = TRIM(appo))
END FUNCTION int2str
The function, being elemental, is a scalar function (in my case it takes one scalar integer and gives back one scalar character, even though allocatable in length) that applies elementwise to arrays.
Why the output of
print *, '>>>'//int2str([1, 3, 5, 7])//'<<<'
is (unexpectedly to me)
>>>1<<<>>>3<<<>>>5<<<>>>7<<<
whereas the output of
print *, '>>>', int2str([1, 3, 5, 7]), '<<<'
is (expectedly)
>>>1357<<<
?
What I mean is that the function should apply to every one of the four scalar integers composing the array, thus returning a length-4 array each element of which being a string, but it seems to me that its elementwise-ness applies to the whole concatenation of three strings, as though the //
operator has precedence over the function's result.