-
Notifications
You must be signed in to change notification settings - Fork 16
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
Pros and Cons of making keywords reserved #167
Comments
(I failed to find the definition now of "semi-reserved keywords". When I researched this about a year ago, I thought that's exactly what Fortran does. But perhaps the term means something else. Either way, that does not change the details of the above issue.) |
@certik wrote:
I've wondered about this as well. Keeping in mind Fortran does not have a concept of NAMESPACEs but the language standard does have a concept of a Possible names for this new prefix-spec are For example, MODULEs and SUBMODULEs are scoping units as is a main program, or an external subprogram, or an interface body, a derived type definition, a BLOCK construct, etc. Say the language allowed PURE module foo_m !<-- Suggested new prefix-spec
use ..
..
<some_type>, parameter :: ..
type :: t
..
end type
interface ..
..
end interface
..
contains
subroutine ..
..
end subroutine ..
..
function ..
..
end function ..
..
end module .. And this were to inform the processor the above scoping unit cannot have a name clash in any entity in that scope with any of the keywords in the language, as listed by @certik above, then I think it provides a way to enforce a good coding practice (GCP) while also enabling better/faster tooling with such "clean" codes in Fortran. Just a thought, |
@FortranFan good point, I haven't thought of that. I really like the #83 approach, so there would simply be |
I disagree that there are ANY reserved or "semi-reserved" words in Fortran. At most there are syntax rules prohibiting statements that look like END but aren't. I've worked on Fortran parsers, so I think I would know if any kind of reserved words existed. A Fortran parser doesn't know about any reserved words. @certik , please indicate why you think some words are "semi-reserved". Examples would be helpful. [Edited to be more constructive.] |
@sblionel this comment comes off a tad aggressive. Please keep in mind our Code of Conduct, in particular we would like to create a welcoming environment for everyone here. Respectful disagreement is always encouraged! |
I thought I was respectfully disagreeing. If you think otherwise, please shoot me an email and explain. |
I edited the issue description and changed "semi-reserved" to "non-reserved". As I mentioned above, I was not sure about the terminology. Since Steve asked, here is an example that Intel Fortran rejects, because it uses a keyword: parameterx = parameterx
end You have to compile in fixed-form mode ( Finally, I should mention that people have asked me why we cannot make keywords reserved in Fortran that it would simplify a lot of things. So this is not some academic exercise. The community asked us, and I see it as our job to have a good answer plus associated discussion why this cannot be done (if that is the case). |
That example fails because, in fixed form, it uses a non-standard feature, the "typeless PARAMETER" statement. This had been part of FORTRAN 77 right up until the final version, where it was changed to the form in the standard today with parentheses and a typed value.
DEC Fortran went ahead and implemented the typeless form because they thought it would become standard. Then they had to support both. This experience resulted in the DEC team (now Intel) refusing to implement features before they become published (either in a standard or a TS.) A compiler without this extension would not have this problem. The example you presented does not reflect the standard. |
Indeed, I verified that gfortran compiles this without a problem. |
Coming across this thread from a different context, but I do sometimes allow myself to use some of the words in the words in the Ondrej's list. In particular, to emulate STL containers, I allow myself to have type-bound procedures named |
Currently Fortran has non-reserved keywords: words like
begin
,end
,subroutine
,result
can be freely used as variable names, but they also have semantic meaning in the right context.Here is a full list of the non-reserved keywords:
The advantage of these being non-reserved keywords is that the standard can add new keywords in the future and they will not invalidate current code, because users can still use them as variable (or function, module, etc.) names.
The disadvantages are:
result
as if they were keywords, even though they are not in that context (that is because the syntax highlighters are based on regex expressions, as opposed to using a full Fortran parser that could disambiguate semi-reserved keywords)Furthermore, in my own codes and other codes, I recommend not to use these non-reserved keywords as variable names anyway. For example, one should not write code like this, even though it's strictly speaking valid:
I opened this issue so that we can brainstorm what can be done about this. Here is an idea:
The text was updated successfully, but these errors were encountered: