Is this always true?
In the F202X (now F2023) proposals, there were multiple versions of split:
SPLIT (STRING, SET, TOKENS [, SEPARATOR])
SPLIT (STRING, SET, FIRST, LAST)
SPLIT (STRING, SET, POS [, BACK])
which can be implemented in Fortran and exported under a generic interface:
interface split
module procedure :: split_tokens, split_first_last, split_pos
end interface split
As long as the split
routines in shlex have arguments which differ in type, kind, and rank, the specific routine needed can be resolved.
One caveat in this case is that the intrinsic split is a subroutine, whereas in fortran-shlex, split is a function. This is prohibited as demonstrated by this example:
module bar
private
public :: random_number
interface random_number
module procedure random_pair
end interface
contains
subroutine random_pair(a,b)
real :: a, b
call random_number(a)
call random_number(b)
end subroutine
end module
module foo
use bar
type :: pair
real :: a, b
end type
interface random_number
module procedure random_pair
end interface
contains
function random_pair()
type(pair) :: random_pair
call random_number(random_pair%a,random_pair%b)
end function
end module
which fails to compile with the following error:
/app/example.f90:16:4:
16 | use bar
| 1
Error: In generic interface 'random_number' at (1) procedures must be either all SUBROUTINEs or all FUNCTIONs
Compiler returned: 1
Addendum: the rule above does not apply for the case of intrinsics. I can modify the module bar as follows:
module foo
!use bar
type :: pair
real :: a, b
end type
interface random_number
module procedure random_pair
end interface
contains
function random_pair()
type(pair) :: random_pair
intrinsic :: random_number
call random_number(random_pair%a)
call random_number(random_pair%b)
end function
end module
But now, as @everythingfunctional says, the intrinsic subroutine is shadowed.