j3-fortran / fortran_proposals

Proposals for the Fortran Standard Committee
178 stars 15 forks source link

Allow multiple levels of internal routines #63

Open arjenmarkus opened 4 years ago

arjenmarkus commented 4 years ago

Just a thought: currently internal routines can not contain internal routines themselves. There is probably a good reason for that restriction, but I am unaware of it. Allowing internal routines to contain internal routines in turn may be useful in large programs or complicated tasks. Of course, it may also mean an inordinate additional complexity for compiler implementation. I would like to discuss the pros and cons for this idea.

certik commented 4 years ago

I was also wondering about this. It might become a little bit hard to read if you nest subroutines a few times. That's the only reason I was able to think of.

tclune commented 4 years ago

In general, the Fortran standard has made some "interesting" choices with regard to nesting of language structures. My guess aligns with Arjen's conjecture that the largest impediment is the difficulty of doing this in the compilers. But the language in the standard may be tricky to change as well.

Aside from generality, though, is there a compelling use case where something reasonable cannot be done with a sibling internal procedure?

arjenmarkus commented 4 years ago

I have no compelling case myself, other than the feeling that it is a non-essential limitation.

arjenmarkus commented 4 years ago

As a side remark: though it may seem non-essential, that is not a good reason in itself of course to have it in the language. Tom may be quite right: a formal description and a thorough analysis of such a feature might very well lead to very convoluted language.

klausler commented 4 years ago

Multiple levels of nested subprograms (when used) would complicate the implementation of access to escaping host-associated variables.