(j3.2006) RECURSIVE

Malcolm Cohen malcolm
Sun Oct 25 21:05:30 EDT 2015


<<<
1) F2008 prohibits (C1245) the prefix combination of ELEMENTAL and 
RECURSIVE.  This is (naturally) missing in F2015.  The wording seems 
carefully crafted to not require the NON_RECURSIVE keyword in any function 
definition, so there would not be literal incompatibilities with F2008, 
though it took a while to prove that theorem.   A Note in this subclause 
might be helpful in explaining that RECURSIVE is the default, but that a 
procedure could be nonrecursive without specifying NON_RECURSIVE.
>>>

Not so.  "Procedures, including elemental procedures, can be invoked 
recursively by default."  right there in the Intro.

There is no prohibition whatsoever against elemental procedures being 
recursive, which indeed they are by default.

<<<
2) Note 7.31 in in the F2015 draft 15-007r2 [154:4+]  (unchanged from F2008) 
the last sentence:

"The prohibition against recursion avoids the creation of a new instance of 
a procedure while construction of one is in progress.?

talks about the prohibition of certain recursive procedures being 
specification functions.
>>>

Sorry, no it is not, and never was.  It is a prohibition against recursion 
into the procedure with the specification expression, not a prohibition 
against recursion of the specification functions.  Specification functions 
have been allowed to be recursive since Fortran 2003, it was only Fortran 95 
that forbade that.

<<<
A specification function in an F2008 program that lacked the RECURSIVE 
prefix would hopefully never be called recursively. So, no issue for the 
compiler to check further.
>>>

Not so.  A nonrecursive function was not ALLOWED to be called recursively, 
but the compiler needs to do a runtime check if it wants to actually detect 
that (except in the trivial direct recursion case, or unless enough of the 
program can be seen, and is simple enough to analyse, to confirm whether 
recursion might be possible).

There is no connection here with specification functions.  Even 
specification functions that are declared to be NON_RECURSIVE could invoke 
the procedure containing the specification expression without those 
functions violating the nonrecursion rule themselves.

<<<
  However, the implementation of the function might be different in the new 
standard (where recursive is assumed), and the ability to check for correct 
usage of a function that is presumed nonrecursive without having been 
declared NON_RECURSIVE is diminished.
>>>

Not so.

There would be no difficulty detecting recursion into a procedure while its 
preamble is being executed, should the compiler make the unlikely decision 
to actually detect that particular form of invalid recursion.

Cheers,
-- 
........................Malcolm.




More information about the J3 mailing list