[J3] Elemental and optional arguments

Malcolm Cohen malcolm at nag-j.co.jp
Mon Jun 28 08:27:13 UTC 2021


On 27/06/21 10:17, John Reid wrote:
> The standard has no concept of  "graphically present". 
> defines the meaning of "present" and uses it.

Maybe "textually present" would have been a better choice of words, but 
that AFAIK is not defined in the standard either.


No words are needed. Actual arguments are actual arguments, this is well-defined.


Anyway what I meant to distinguish was "call foo()" and "call foo(a)" 
were "a" would be considered absent under


The first has no actual argument at all.

The second has one actual argument.

There is no concept of “textually present”, an actual argument is an actual argument.


And the concept of presence only applies to dummy arguments. So it only makes sense for an actual argument to be “absent” if it is itself an optional dummy argument.


Basically, argument presence is transitive, so when you pass an optional dummy down as an actual argument corresponding to an optional dummy in a third routine, the dummy in the third routine has the same “presence” as in the caller.


So in your example here, inside “foo” the effect is the same whether there is no actual argument or the actual argument is an absent dummy or an unallocated allocatable or a disassociated pointer (the last two only when being passed to an optional nonallocatable nonpointer dummy).


I am trying to distinguish two different situations.

First, a procedure passing an optional dummy argument, which is my 
understanding that the whole applies to.

Second, a subprogram passing an allocatable or pointer variable, which 
may only be known if it is present or not, under, at runtime.


Both of these are only known at runtime. There is no difference there.



>> A corollary of these two assumptions would be that shape conformance 
>> of graphically present actual arguments is mandatory, without regard 
>> to presence in the sense of, and reduces to rank matching.
> No.


I think this text in the standard is poorly written, possibly even defective. Anyway, shape conformance never “reduces to rank matching”.


(We should probably split this sentence into a requirement that all nonscalar actual argument have the same rank, and a requirement that all actual arguments that are not absent dummies or disassociated pointers or unallocated allocatables have the same shape.)



>>   ! In principle it is only possible to know if a is present at runtime,
>>   ! so this is most likely illegal. Although I don't know why has I
>>   ! don't think (6) applies here.
>>   b = efun(a)


This requires a to be allocated, otherwise “the shape of the result is the same as the shape of the actual argument with the greatest rank.” has no meaning, as an unallocated array has no shape.


I think that (6) should apply to the case of unallocated allocatables and disassociated pointers as well as absent dummies. We should probably make this an explicit rule.




..............Malcolm Cohen, NAG Oxford/Tokyo.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20210628/06067fa4/attachment.htm>

More information about the J3 mailing list