Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Namespace for modules #1

Open
certik opened this issue Oct 16, 2019 · 103 comments
Open

Namespace for modules #1

certik opened this issue Oct 16, 2019 · 103 comments
Labels
Clause 14 Standard Clause 14: Program units Fortran 202y Proposals targeting the standard after F2023 under consideration Has been submitted to the committee

Comments

@certik
Copy link
Member

certik commented Oct 16, 2019

So you can require module data to be referenced like module.var:

use, namespace :: utils
...
call utils%savetxt()

One issue with just use utils is that it still pollutes your local namespace with savetxt, so that's the reason for use, namespace :: utils.

Other alternatives for syntax: use utils, only (or perhaps use utils, only:). Another alternative is use namespace utils (suggested by Milan Curcic). Or perhaps use, namespace :: utils, to by compatible with the existing syntax like use, intrinsic :: iso_fortran_env.

Initially proposed by Michael Zingale and further discussed at Twitter.

@zjibben zjibben added the unsubmitted Has not been submitted to the committee yet label Oct 16, 2019
@certik
Copy link
Member Author

certik commented Oct 16, 2019

The paper is submitted at https://j3-fortran.org/doc/year/19/19-246.txt. I will try to get feedback on it from the committee. CC @zingale.

@certik certik added under consideration Has been submitted to the committee Fortran 202y Proposals targeting the standard after F2023 and removed unsubmitted Has not been submitted to the committee yet labels Oct 16, 2019
@cmacmackin
Copy link

Agree, this seems like a good feature.

@certik
Copy link
Member Author

certik commented Oct 21, 2019

So the committee unfortunately did not consider this proposal at the meeting last week. I was hoping to get at least a general "yes" or "no" direction from the committee. But I talked to a few members directly, and I did not hear any "this is a bad idea", or "this should not be done".

Here is my plan:

  1. Write a high quality full proposal for this. This means more use cases, we have to brainstorm any possible issues, and some members of the committee like to structure any new features as "requirements", "specification" and "syntax", so we should incorporate all that.

  2. I will ask on the j3 mailinglist once a more complete proposal is ready to get some feedback

  3. I will ensure that this gets to the committee program for next meeting to be officially considered for the 202y standard.

@certik
Copy link
Member Author

certik commented Oct 23, 2019

@septcolor that's a valid concern. My plan to overcome this is to use this github repository to get support for proposals. If the Fortran community puts thumbs up for a proposal, or otherwise expresses strong interest, then relatively to other ideas proposed here it will be obvious which proposals are high priority, and which are low priority. And then it will be easier to argue for a particular proposal at the committee.

@FortranFan
Copy link
Member

FortranFan commented Nov 3, 2019

Fyi a new thread at comp.lang.fortran inquiring of a missing feature in current Fortran which can be met by the proposal here:
https://groups.google.com/d/msg/comp.lang.fortran/nYdFG0PCTWo/rjjLlAteDgAJ

By the way, I had a similar interest along the lines of this proposal several years ago:
https://groups.google.com/forum/#!msg/comp.lang.fortran/sNNnQaoqC9I/JFAEgsbeAPMJ

@certik
Copy link
Member Author

certik commented Nov 3, 2019

Thanks @FortranFan. This is one of the popular issues in here and I am going to insist for the committee to consider it at the next meeting. However, I welcome any help with improving the current proposal (linked above).

@FortranFan
Copy link
Member

@certik wrote:

..However, I welcome any help with improving the current proposal (linked above).

@certik and others interested in this, if you haven't already please take a note of comments online, especially by Ian Harvey at comp.lang.fortran such as this one:

Look at the last 3 questions in that comment: addressing these questions suitably will strengthen the proposal. Some aspects that come to my mind with these questions include:

  1. USE statements can include unnamed operators (+,-*,/, etc.), assignment(=), etc. What is the impact of this proposal on their semantics?
  2. What about named entities which are operators in USE statements e.g., operator(.cross_product.)? Does x .cross_product. y become x foo::operator(.cross_product.) y a la C++?
  3. What about generic interfaces and their extension via USE statements?
  4. Current standard has scoping unit semantics with MODULE subroutines/functions (e.g., for use in SUBMODULEs), INTERFACEs. BLOCK constructs, etc. that can be impacted by USE statements. What happens with them?

@certik
Copy link
Member Author

certik commented Nov 6, 2019

@FortranFan thanks a lot for pointing these potential issues out. Let's address them.

This was referenced Nov 14, 2019
@gronki
Copy link

gronki commented Nov 19, 2019 via email

@qolin1
Copy link

qolin1 commented Dec 21, 2019

Gets my vote FWIW. I have wanted this for some time, without knowing its name was "namespaces".

@certik
Copy link
Member Author

certik commented Dec 22, 2019

@qolin1 I just called it "namespaces" for a lack of a better name. We will keep pushing for this at our next committee meeting. I think this is a popular feature.

@gronki
Copy link

gronki commented Dec 23, 2019 via email

@certik
Copy link
Member Author

certik commented Dec 23, 2019

@klausler, @gronki make sure you put thumbs up on issues that you find high priority, and let's collaborate on the top priority issues. I just created #122 for that purpose, let's discuss the list of top priority issues there.

Regarding this issue #1, for me personally this is a huge quality of life improvement, that is a relatively simple feature, and yet it allows to use Fortran modules more like Python. How this stacks up against some other features that we want to push in terms of prioity, that's for a discussion to be had at #122.

@jme52
Copy link

jme52 commented Jan 16, 2020

  1. I think this is a good idea.
    I worked for many years in a code where policy was that module procedures needed to start with the name or the acronym of the module. This would make that code neater.

  2. I like the use, namespace :: utils syntax. I think namespace should be optional and disabled by default for backwards compatibility (sorry if I am stating the obvious).

  3. I agree that % is the fortranic syntax. However, its use may increase the complexity of the rules about scope of identifiers, which will need to be significantly rewritten.

  4. Would it be possible to simultaneously add the possibility of renaming modules (namespaces) as part of the use declaration?

    use, non_intrinsic, namespace :: eh => electronic_history
    implicit none
    call eh%initialise_method

@everythingfunctional
Copy link
Member

I like the idea of namespaces, and I like @jme52 syntax example, use, namespace :: sm => some_module, but one thing that should be pointed out is that you would not then be able to do use, namespace :: sm => some_module, only: thing1, thing2. Or at least I don't think you should be able to. Just thought this should be made explicit.

@jme52 , Why do you think using % increases the complexity of rules about scope? Do you have an example of that?

@smeskos
Copy link

smeskos commented Sep 26, 2020

@wclodius2

Are there any names I missed?

The word name itself as a verb or the word rename.

However, I find all of the proposed keywords as non-Fortranic way of doing things. With the only exception perhaps of the original proposal of namespace.
An example of my personal favorite style of implementing this:

use mathematics, only: cdif=>central_difference
call cdif()
!to
use, namespace, math=>mathematics, only:cdif=>central_difference
call math%cdif()

The keyword namespace will be employed to distinguish between using or not using the name of the module and the symbol => optionally if we want to rename locally the name of the module.

Another alternative to namespace could be modulename, only because the former may cause confusion with the C++ keyword, and why not to reserve it for a possible future similar implementation.
Therefore, the alternative to my previous example:

use, modulename, math=>mathematics, only:cdif=>central_difference
call math%cdif()

@FortranFan
Copy link
Member

FortranFan commented Sep 26, 2020

I will request everyone to take a look at my comment in another thread #86, a thread with another proposal that I think is along the same lines as this one. As I suggest therein, I personally would preface NAMESPACE to reflect a formal concept that is waiting to be introduced in the Fortran standard at some later stage in the advancement of this language. Fortran being a language that always holds tremendous promise as a tool for scientists and engineers but which is perpetually trying to "catch up" to the state-of-the-art in technical computing. Meaning the language and its bearers haven't fully caught up yet to the concept of namespace and its benefits though Fortran did a take a big step toward it with MODULEs introduced back in 1991 with the Fortran 90 publication.

In the context of this particular proposal in this thread, I think the search is for a way to decorate module entities suitably during their "consumption" via USE association.

And I think the Fortrannic way will be to introduce both an ATTRIBUTE and a STATEMENT for the same. And where the options gain a FUNCTION-like syntax with optional arguments within parenthesis.

There are several examples of this in the Fortran standard: ALLOCATABLE, BIND, etc. BIND seems to me to be quite apt here for understanding a facility that is both an ATTRIBUTE and a STATEMENT. Note the token BIND in my simple-minded thinking can be viewed as a verb or a command or an instruction which is what seems to be the need here.

So thinking along the same lines, an alternate suggestion will be to use DECORATE as the token:

use, decorate :: utils 
..
call utilsXsavetxt(..)

where X is the separator yet to be decided; it can be % (as in call utils%savetxt(..)) or it might be double-colon (as in call utils::savetxt(..)), etc.

And additional options with (re)naming can be introduced as

use, decorate( name="ut" ) :: utils 
..
call utXsavetxt(..)

With the STATEMENT form, the expected syntax is

use utils
..
decorate :: utils
..
call utilsXsavetxt(..)

Applying the same to @smeskos 's examples above, I would expect the syntax to be

use, decorate(name="math") :: mathematics, only : cdif => central_difference
call mathXcdif()

And if the optional name is not employed,

use, decorate :: mathematics, only : cdif => central_difference
call mathematicsXcdif()

With the example in the J3 paper (https://j3-fortran.org/doc/year/19/19-246.txt), the syntax can look like so:

    use, decorate :: math
    use, decorate( name="np" ) :: numpy
    use, decorate( name="sym") :: sympy
    ...
    e1 = npXsin(npXpi)      ! NumPy expression
    e2 = mathXsin(mathXpi)  ! Built-in Python math expression
    e3 = symXsin(symXpi)    ! SymPy expression

and

    use, decorate :: lapack
    ..
    call lapackXdgeev('N', 'V', n, At, lda, wr, wi, vl, ldvl, vr, ldvr, &
     work, lwork, info)
    ..
    call lapackXdgetrf(n, n, Amt, lda, ipiv, info)
    ..

@gronki
Copy link

gronki commented Sep 27, 2020 via email

@milancurcic
Copy link
Member

I also like @FortranFan's idea of specifying the namespace name in parentheses following the keyword. Also with @gronki that the new name shouldn't be a string literal.

I don't like the word "decorate" here. To me it means to add functionality to something which I don't think is what we're doing.

@FortranFan
Copy link
Member

FortranFan commented Sep 27, 2020

@gronki, @milancurcic ,

I'm ok with the synonym to be not a string literal i.e., a default-char-constant-expr per the standard. I had suggested as much based on what I thought I had heard previously with certain compiler implementations and how they parse the FUNCTION-like approach with the use of parenthesis in ATTRIBUTEs and STATEMENTs. This is where an implementation or two, as suggested by @certik, will come in handy: it can help work through such options.

@milancurcic ,

Re: "I don't like the word "decorate" here. To me it means to add functionality to something which I don't think is what we're doing.":

  • note this proposal is indeed adding a functionality, albeit it is in the form of an adornment or an embellishment that makes something distinguished. What might previously be a use-associated entity FOO from MY_MOD module will no longer have its first-class (or an independent) identity that it has with current standard. Meaning, there can no longer be a reference to FOO in that scope. It must be "adorned" as something like MY_MOD::FOO (or MY_MOD%FOO, depending on the separator chosen.)

Then, in the dictionary sense of the term, this is nothing but decoration. That's why I suggested that token. It seems to better capture the essence of the functionality being proposed here than all the alternatives suggested upthread.

But if it's too verbose, another alternative is ADORN.

By the way, I had thought of DISTINGUISH and EMBELLISH also because in a sense with the PI example shown above with Python packages, this proposal is in a way seeking an easier way to distinguish/embellish the entities from each other in a given scope. It seemed even more verbose or negative-sounding, so I decided against it.

Now, if people starting getting too much into further nits with the choice of the word, that will confirm @wclodius2 's point earlier about the bikeshedding here.

@gronki
Copy link

gronki commented Sep 27, 2020 via email

@milancurcic
Copy link
Member

@FortranFan Thank you, only after your detailed explanation I was able to understand--you're not decorating the module itself, but the public entities in the module. Now it makes more sense.

I'd still advise against it because of how easily it can be confused with decorating as a software design pattern. For example, if I was teaching this concept, I'd have to caveat it with something like "If you've used decorators in other languages before, be careful--this does something completely different", and then refer to it as "namespace" in the rest of the material. :)

This is also a good example of why I think the choice of the word is important.

@FortranFan
Copy link
Member

@septcolor wrote:

..
And one more possibility may be this form? ..
.. USE hitechlib AS ht

As mentioned upthread, punctuation or a separator between conjunctions is needed to support the 2 sources forms in Fortran, and that's why this does not work.

@certik
Copy link
Member Author

certik commented Sep 28, 2020

Thanks everybody for your input and making progress on this issue.

@septcolor raises an important thing to consider: #86 (nested modules). As posted there, this might work:

use, namespace :: mylib%a
...
call mylib%a%something()

I like the :: option instead of % also, but I don't know if it will work syntax wise for nested modules:

use, namespace :: mylib::a
...
call mylib::a::something()

Don't know if there could be issues parsing it.

Another issue to consider is nested modules (proposed feature as in #86) versus modules using other modules (existing feature) with regards to syntax and importing. E.g., does call mylib::a::something() work for both a being a nested module, versus a being used inside mylib?

@wclodius2
Copy link
Contributor

wclodius2 commented Oct 1, 2020

There seems to have been a consensus that there should be a poll/vote on the preferred syntax. As there has been a significant pause in postings on this issue, I think it is an appropriate to summarize our current syntactic options to prompt more suggestions for options. There are four orthogonal choices in the syntax:

  1. What word to use as the keyword
  2. Where to put the keyword
  3. How to do module renaming
  4. What to use as the accessor "operator"

What word to use

So far I have seen the following suggestions for keywords:

  • adorn - a shorter version of decorate
  • as or as is - one for renaming the other for non-renaming. What happens if you want to rename to is?
  • decorate - slightly long, has a dirfferent meaning in software engineering
  • employ - a synonym to use
  • import - used for this in Python, but already a keyword with different semantics
  • namespace - main problem is its length, but users of C++, where namespace behaves like Fortran's use, may find this usage counterintuitive
  • ns - an abbreviation for namespace that is similar to nanosecond
  • only - only as a use statement terminator, overloads its current meaning
  • qualified - one of its meanings is suggestive of the semantics, but not the most commonly used meaning, as long as namespace
  • source - slightly suggestive of the semantics
  • using - similar to use, slightly suggests requiring the module name to access
  • with - main advantage is its length, some find it unintuitive

Are there any names I missed? With this many options it might be best to do a ranked choice vote.

Where to put the keyword

I know of three possible places to put the keyword

  1. At the beginning, making its own statement, i.e, keyword[[, module-nature]::] .... This is what most of the languages cited do.
  2. After the use keyword: use [[, keyword][, module-nature]::] ... or use [[, module-nature][, keyword]::] .... It will be tempting to lump the keyword with intrinsic and nonintrinsic in module-nature, in which case the standard needs to explain that there is no only or rename list.
  3. Replacing the only keyword: use[[, module-nature]::] module-name, keyword[:local-module-name]
    making a third form of a use statement.

How to rename modules

I have noted three ways to do module renaming:

  1. Use a syntax based on the rename list of the use statement [local-module-name=>]module-name, e.g.,
  • keyword[[, module-nature]::] [local-module-name=>]module-name
  • use [[, keyword][, module-nature]::] [local-module-name=>]module-name
  • use [[,module-nature]::][local-module-name=>]module-name, keyword
  1. After the colon after the module name where the keyword replaces only: use [[,module-nature]::]module-name, keyword[: local-module-name]
  2. In a parenthesized rename after the keyword
  • keyword[([name=]local-module-name)][[, module-nature]::] module-name
  • use [[, keyword[([name=]local-module-name)]][, module-nature]::] module-name
  • use [[,module-nature]::]module-name, keyword[([name=]local-module-name)]

What to use as accessor operator

I have noted two suggestions for the accessor operator

  1. %, used as the accessor for derived types
  2. ::, used extensively in the specification-part, but not in the execution-part of Fortran programs/subprograms. The main question is would its use cause what is intended to be an executable statement, to be interpreted as a specification statement, i.e., could a module name be the same as the start of a specification statement.

In principle other characters could also be used: backtick, ~, @, ^, |, and \ are ASCII characters not used by Fortran, and, I believe, not used by the common pre-processors.

FWIW I tend to prefer the shorter keywords, but dislike overloading the meaning of "only" and "import". So my first preference is with followed by using and adorn. I believe modifying the use statement to incorporate the keyword, will more complicate the standard than having a keyword statement, so I prefer a keyword statement. Because I don't want a modified use statement, I don't want the rename after the colon after the keyword. I don't have strong feelings about keyword[([name=]local-module-name)] versus [local-module-name=>]module-name. I prefer the accessor to be the same as for derived types, i.e., %, but :: would also be acceptable.

Edit: Formatting by @milancurcic for readability

@milancurcic
Copy link
Member

Thank you for the summary @wclodius2, it's very helpful. Here's my current preference:

  1. What word to use: as (renaming) and as is (non-renaming)
  2. Where to put the keyword: Option 3: use[[, module-nature]::] module-name, as[: local-module-name]
  3. How to rename modules: use[[, module-nature]::] module-name, as is
  4. What to use as accessor operator: Aesthetically I like :: best. If it's problematic due to issues you raise, I like either % or @. Others I don't like.

Examples:

  • use stdlib_stats, as: stats
  • use stdlib_stats, as is

Addendum to the syntax proposal which would allow orthogonal imports as @klausler suggested: It's possible to use the only keyword following the as: local-module-name, so the syntax becomes:

use[[, module-nature]::] module-name, as[: local-module-name][, only: [local-entity-name =>] entity-name]

Example:

use stdlib_stats, as: stats, only: mean, var

This statement would import stdlib_stats as a stats namespace (with all public entities therein available via the namespace), and also import mean and var into the global namespace.

To prevent writing confusing code, as would have to appear before only if both are used. So

use stdlib_stats, only: mean, var, as: stats

shouldn't be allowed IMO.

@milancurcic
Copy link
Member

I didn't think about that. It does seem like the most elegant solution. Simply make it available as a namespace if you don't need it renamed. It's backward compatible because, as you say, it has been impossible to reference a module name after a use statement. I like it.

@wclodius2
Copy link
Contributor

wclodius2 commented Oct 1, 2020 via email

@milancurcic
Copy link
Member

some users will want the processor to enforce the use of the module name as a qualifier which in turn requires the use of a different syntax to let the processor know that that is a requirement.

Indeed, once you can namespace, simple and common names will proliferate in modules and the user should have a way to not have them pollute the global namespace.

@certik
Copy link
Member Author

certik commented Oct 1, 2020

@klausler That seems to be a very similar idea to what I proposed above #1 (comment), but I thought you didn't like it. Are you proposing exactly the table in that comment, or are you proposing the following table (in other words, do you want to allow use A, only: or not):

Case Python Julia Chapel Fortran
1. import A import A use A only use A
2. import A as B import A as B use A as B only use B => A
3. from A import x using A: x use A only x use A, only: x
4. from A import x as y import A: x as y use A only x as y use A, only: y => x
5. from A import * using A use A use A

Furthermore, in all cases 1.-5., the module name A (or B in 2.) will always be created as a namespace, in addition to importing all the symbols from it in 1., 2. and 5. (and only x or y in 3. and 4.).

If the above is what you are proposing, I can see all kinds of extensions in the compiler, for example with an option the compiler can start warning (by supplying -Wimplicit-use) if you do use A but use any implicitly imported symbol from the module (in case 1.), and if you want to use case 5. and not get a warning, you can do use A, only: *. The syntax would be natural, and I would enable that -Wimplicit-use warning option for my codes (I currently never use use A anyway). In this case, it would make sense to consider adding the syntax use A, only: * into this proposal also, to make it standardized: in other words, use A, only: * would be equivalent to use A, but the compiler would only warn if you use some symbol implicitly in the latter case. That should be strictly backwards compatible, and yet doing exactly what I would like. People who don't like this (or for older codes) would just not enable the -Wimplicit-use compiler warning.

@certik
Copy link
Member Author

certik commented Oct 1, 2020

Ok, so to summarize, you are proposing this:

Case Python Julia Chapel Fortran
1. import A import A use A only use A, only:
2. import A as B import A as B use A as B only use B => A, only:
3. from A import x using A: x use A only x use A, only: x
4. from A import x as y import A: x as y use A only x as y use A, only: y => x
5. from A import * using A use A use A

Where the cases 1. and 2. are exactly equivalent to Python, but cases 3., 4. and 5. are a "superset" of Python: they import the x, y or all symbols as in Python respectively, but also in addition make the module name A available as a namespace in Fortran (which does not happen in Python).

I like this proposal.

@certik
Copy link
Member Author

certik commented Oct 1, 2020

Thanks Peter. My goal is to get it pre-approved by the committee, saying "yes, we want this feature, as long as all the issues can be satisfactorily resolved". The minute it does, I am sure multiple people from the community will help. Obviously nobody wants to put in weeks of work if the committee decides they don't want this feature in the first place.

I plan to prototype this in a compiler.

@FortranFan
Copy link
Member

FortranFan commented Oct 1, 2020

@klausler wrote Oct. 1, 2020 6:48 PM EDT:

The harder part of this proposal remains to be discussed, too. ..

I agree.

As I alluded to earlier, Fortran language can do better by gaining the formal concept of namespaces. Ideally, features such as this are best handled as part of that effort.

Considering the complexities and constraints involved with piecemeal attempts, a prototype implementation for the formal namespace concept itself will be nice. The aspects such as this thread can be subparts of such an initiative.

@certik
Copy link
Member Author

certik commented Oct 2, 2020

I personally feel we don't need namespaces, but I agree with Vipul that we should keep it in mind and not close doors by introducing something that would make it very hard to introduce namespaces later if the community wishes that.

Modules and a well designed "import" is what I personally would like to see. Fortran is very close.

@septcolor regarding who can contribute: I strongly encourage you and anyone else to contribute. The committee and the community is composed of both users and compiler vendors / experts, and we need both to collaborate on new features. Leaving things just to compiler vendors, or just to users to design is not optimal, we need a healthy collaboration of both groups.

@FortranFan
Copy link
Member

@wclodius2 wrote Oct. 1, 2020

There seems to have been a consensus that there should be a poll/vote on the preferred syntax. As there has been a significant pause in postings on this issue, I think it is an appropriate to summarize our current syntactic options to prompt more suggestions for options. There are four orthogonal choices in the syntax:

What word to use as the keyword
..

If there are folks who aren't enthused by any of the keywords thus far, here's another one that can perhaps considered for the poll? PREFIX:

use, prefix(ut) :: utils, only : savetxt
..
call utXsavetxt(..)

@milancurcic milancurcic added the Clause 14 Standard Clause 14: Program units label Oct 27, 2021
@aradi
Copy link
Contributor

aradi commented May 9, 2022

I think, the idea with prefix is a really nice one. But, maybe prefixed (as adjective) is more aligned with what we have already, e.g.

use, intrinsic, prefixed :: iso_fortran_env        ! if entire module name is used as prefix
use, intrinsic, prefixed(ife) :: iso_fortran_env  ! if specified prefix is used

@certik certik mentioned this issue May 13, 2022
@beddalumia
Copy link

beddalumia commented Sep 17, 2022

  • use stdlib_stats, as: stats
  • use stdlib_stats, as is

I would find it rather confusing, not the first one, which I think is neat, but the second: "as is" makes me think about "as given" / "raw" / "as provided", so equivalent to the current behavior withuse stdlib_stats (which I hope you want to preserve: there are cases where one wants a namespace, there are cases where it just adds unnecessary verbosity, that's why python offers also the from x import z syntax).

What about

  • use stdlib_stats, as namespace: stats
  • use stdlib_stats, as namespace

instead?

I find it very "natural-english-alike", which is imo what Fortran has always striven for...

@shahmoradi
Copy link

How about

use, intrinsic, namespace :: iso_fortran_env        ! if the entire module name is used as a prefix
use, intrinsic, namespace :: ife => iso_fortran_env  ! if the specified prefix is used

@aradi
Copy link
Contributor

aradi commented Sep 18, 2022

use, intrinsic, namespace :: ife => iso_fortran_env ! if the specified prefix is used

I think, that would be quite Fortranic and nice, I like it a lot! Only, I'd rather go with an adjecive (prefixed or namespaced) here, as it reads very nicely: "Use the intrinsinc, prefixed module iso_fortran_env"

@beddalumia
Copy link

beddalumia commented Sep 18, 2022

Maybe prefixed, namespaced does not look that much like english :)

@ivan-pi
Copy link

ivan-pi commented Sep 24, 2022

Does this usage case help motivate the namespace proposal?

I have a clash between a dummy argument name and a typename.

module object_module
type :: object
end type
contains
subroutine handle_object(object)
class(*), intent(in) :: object
select type(object)  ! the variable
   type is (object)  ! the typename
      ! do something
end select
end subroutine
end module

To resolve the name clash, I have the following options

  1. Pick a different name for the object dummy argument. Since Fortran dummy argument names are part of the public interface, this may not be desirable as it could break existing code.
  2. Pick a different name for the derived-type. Also not desirable as it could break existing code.
  3. Place the implementation into a submodule, and re-import the type from a separate module, renaming it in the process, e.g.:
module object_m
implicit none

type :: object
end type

interface 
module subroutine handle_object(object)
class(*), intent(in) :: object
end subroutine
end interface

end module

module rename_object
use object_m, only: object_m_object => object
public
end module

submodule (object_m) object_impl
contains
   module subroutine handle_object(object)
      use rename_object
      class(*), intent(in) :: object
      select type(object)
         type is (integer)
            print *, object
         type is (object_m_object)
            ! ...
      end select
   end subroutine
end submodule

Solution 3 is not very desirable because I suddenly have a new module, just to rename a type. It would be much nicer to just to object_m % object or (object_m) object (copying the (module) submodule syntax) and refer directly to the entity in the parent module.

certik pushed a commit that referenced this issue Jun 30, 2024
Update cmplx-real-pointers.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Clause 14 Standard Clause 14: Program units Fortran 202y Proposals targeting the standard after F2023 under consideration Has been submitted to the committee
Projects
None yet
Development

No branches or pull requests