# Fortran \`shlex\` library

**URL:** <https://fortran-lang.discourse.group/t/fortran-shlex-library/6981>\
**Category:** Announcements\
**Created:** [December 13, 2023, 11:47am UTC](https://fortran-lang.discourse.group/t/fortran-shlex-library/6981 "2023-12-13T11:47:05Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![ivanpribec](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/ivanpribec/32/3290_2.png) [@ivanpribec](https://fortran-lang.discourse.group/u/ivanpribec)\
**Post date:** [December 13, 2023, 8:56pm UTC](https://fortran-lang.discourse.group/t/fortran-shlex-library/6981/5 "2023-12-13T20:56:54Z")

</div>

> [@everythingfunctional](#):
>
> No real conflict. It just shadows the intrinsic, so you can’t use both in the same scope.

Is this _always_ true?

In the F202X (now F2023) proposals, there were multiple versions of split:

```txt
SPLIT (STRING, SET, TOKENS [, SEPARATOR])
SPLIT (STRING, SET, FIRST, LAST)
SPLIT (STRING, SET, POS [, BACK])

```

which can be [implemented in Fortran](https://github.com/milancurcic/fortran202x_split) and exported under a generic interface:

```auto
  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:

```fortran
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:

```txt
/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:

```fortran
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.

---

_[View the full topic](https://fortran-lang.discourse.group/t/fortran-shlex-library/6981)._
