On 5/22/22 10:22 AM, Dan Nagle wrote:
[...]
> The function result variable inherits all the characteristics
> of the function name.
Your claim would seem to apply to both cases, with and without the
result() clause. Yet you have already stated that it doesn't, that it
only applies to the case without the result() clause.
Or are you claiming that with result(r), the entity r is not the result
variable? Or that the entity r does not inherit all the characteristics
of foo, the function name.
Either way, it seems like a contradiction to the above statement?
>
> The statement declaring foo to be a pointer to subroutine
> is invalid because it attempts to change the characteristics of foo.
Yet, with the result() clause you claim that the same thing is allowed.
Isn't this inconsistent with your above argument?
>
> The function statement declares two characteristics of foo:
> 1. foo is a function, and
> 2. foo has no arguments.
Within the body of the function, and without the result() clause,
references to foo are to the result value, not recursive references to
the function. This is the same as if it were say, an integer function.
References within the body would be to the integer value, not recursive
references to the function with no arguments. Here is another example of
this, which I think is conforming:
program func
write(*,*) foo(3)
contains
function foo(n)
integer :: foo(2) ! return an integer array.
integer, intent(in) :: n
foo(1) = -n
foo(2) = n
return
end function foo
end program func
Note that there is no result() clause. The result of the function is an
integer array, so result() is not necessary simply to declare an array
valued function. Also, within the function body, the references to
foo(1) and foo(2) are to the elements of the integer array, they are not
recursive references to the function with its single integer argument.
Is this small program conforming?
[...]
> result was also added to allow the function value to be an array.
The example above shows that result() is not required for this purpose.
> (This is one reason why result variables inherit all characteristics
> of the function name- you want the array to have the correct shape.)
See the above example which contradicts this statement.
>> Without result(), there is no ambiguity that within the body of the
>> function that references to foo are references to the value.
This is demonstrated with the above example. There is no result()
clause, and there is no ambiguity, even though foo(1) looks the same
with either interpretation.
>>> The theme is that one must distinguish the function-ness of foo
>>> from the subroutine-ness of foo's result value. An extra variable does the
>>> trick.
>>
>> Those two "-ness" are already distinguished.
This is demonstrated with the above code for the case of an integer
array. The language already distinguishes between foo(1) as a recursive
function reference and foo(1) as an array reference. The same occurs for
other types, including I believe procedure pointers.
> The ambiguity is that you want some references to foo to be a function,
> and some references to foo to be a subroutine.
There is no ambiguity. Without the result() clause, all references to
foo within the function body are to its value as an integer array in the
above example, and to a procedure pointer in the example being discussed.
>
> Whether foo is a function or a subroutine is a characteristic
> that cannot change.
foo is a function, and its value is a procedure pointer.
> foo is a function because it is the name in a function statement.
> The type of foo is irrelevant.
This statement is not consistent with the above example. There foo is a
function, and the type of its value is an integer array. References such
as foo(1) within the body of the function are to the integer array, not
recursive references to the function.
> foo is not a subroutine because its name does not appear in a subroutine
> statement.
> Attempting to do so by setting the type of the result is not conforming.
Are you claiming that the value of foo cannot be a procedure pointer
that is assigned to a subroutine either with or without the result() clause?
I remember Richard Maine saying that one should never write a function
that returns a pointer value. I'm not sure this is what he had in mind,
but perhaps this discussion reflects the wisdom of his warning.
However, having said that, if I were to write a function that returns a
procedure pointer, I would always use the result() clause to make it
easier for a human to understand, although I think the language is
unambiguous in either the result() or the no result() case.
$.02 -Ron Shepard