For example,
INTERFACE OPERATOR(+)
MODULE PROCEDURE logplus
END INTERFACE
...
PURE LOGICAL FUNCTION logplus(a,b)
LOGICAL,VALUE :: a,b
logplus = a.OR.b
END FUNCTION
For example,
INTERFACE ASSIGNMENT(=)
MODULE PROCEDURE asgnli
END INTERFACE
...
PURE SUBROUTINE asgnli(a,b)
LOGICAL,INTENT(OUT) :: a
INTEGER,VALUE :: b
DO WHILE (IAND(b,NOT(1))/=0)
b = IEOR(IAND(b,1),SHIFTR(b,1))
END DO
a = b/=0 ! Odd number of "1" bits.
END SUBROUTINE
INTEGER FUNCTION factorial(n) RESULT(r)
IF (n>1) THEN
r = n*factorial(n-1)
ELSE
r = 1
END IF
END FUNCTION
is valid, just as if it had been explicitly declared with the RECURSIVE keyword.
This does not apply to assumed-length character functions (where the result is declared with CHARACTER(LEN=*); these remain prohibited from being declared RECURSIVE.
Note that procedures that are RECURSIVE by default are excluded from the effects of the -save option, exactly as if they were explicitly declared RECURSIVE.
ELEMENTAL RECURSIVE INTEGER FUNCTION factorial(n) RESULT(r)
INTEGER,INTENT(IN) :: n
IF (n>1) THEN
r = n*factorial(n-1)
ELSE
r = 1
END IF
END FUNCTION
may be invoked with
PRINT *,factorial( [ 1,2,3,4,5 ] )
to print the first five factorials.
NON_RECURSIVE INTEGER FUNCTION factorial(n) RESULT(r)
r = 1
DO i=2,n
r = r*i
END DO
END FUNCTION
In Fortran 2008 and older standards, procedures are non-recursive by default, so this keyword has no effect unless the -recursive or -f2018 is being used.
For example,
MODULE npa_example
INTERFACE g
MODULE PROCEDURE s1,s2
END INTERFACE
CONTAINS
SUBROUTINE s1(a)
EXTERNAL a
CALL a
END SUBROUTINE
SUBROUTINE s2(b,a)
EXTERNAL b,a
CALL b
CALL a
END SUBROUTINE
END MODULE
This example does not conform to the Fortran 2008 rules for unambiguous generic procedures, because the argument A distinguishes by position but not by keyword, the argument B distinguish by keyword but not by position, and the positional disambiguator (A) does not appear earlier in the list than the keyword disambiguator (B).