On 2016-03-31 12:45 AM, FortranFan wrote:
> On Tuesday, March 29, 2016 at 4:08:45 AM UTC-4, Wolfgang Kilian
> wrote:
>
>> ..
>>
>> I don't see a strong point in a component (ENUM_TYPE%ENUM_VAL)
>> syntax. I'd rather avoid that. The enumerator values are the
>> possible *instances* of the enumerator type, they are not
>> components. I'd go just with the individual names of the enum
>> values, ..
>>
>> One would like to have the enum value names unique within scope,
>> anyway. No need for new concepts of namespace, etc.
>>
>> ..
>
> If I am understanding the statements such as above correctly, they
> seem to override the very needs I have expressed and if so, I find it
> rather worrisome for they betray a lack of understanding and concern
> for the needs of fellow Fortran coders. Is this how the Fortran
> community wants to go about evolving the language?
On the other hand, if someone wants a strongly typed enumeration with
the enumerator identifiers at module scope, consistent with how all
other identifiers work in the language, then your proposal overrides
their "needs".
> I ask what issues or problems might ensue if a more inclusive
> capability of the kind I seek is included in the language; as I said,
> let us not be concerned by non-technical matters at this stage; any
> time and resource constraints of vendors. No one has raised any
> technical, language-related concerns thus far. So from a strict
> language facility point-of-view, what exactly is to be gained by a
> 'lean' feature if that were to leave coders like me in the lurch?
>
> I feel I have explained repeatedly my reason for a syntax like
> ENUM_TYPE%ENUM_VAL or ENUM_TYPE(ENUM_VAL) which is to be able to
> resolve ambiguities with non-unique enum values and to make the code
> clearer to read. Standard bearers of other languages have long
> understood this and provided solutions - see link below for Ada, I
> only mention it because I have heard some on the committee look
> kindly to features in Ada, but that pointing out anything in C++
> (scoped enums, etc.) won't go down too well for whatever reason:
>
http://www.radford.edu/~nokie/classes/320/typesnotes/enum6.adb.html
I think `(` and `)` are already excessively overloaded in the language
(basic statement syntax, function references, implied-do's, array
subscripting, substring subscripting...), to the point that it
compromises source readability, error diagnostics and the ability to
further extend the language. Adding another overload will make that
situation worse.
The confusion that results from overloading of syntax for markedly
different operations is the primary reason that I am not in favour of
using a single `%` token for some sort of namespace resolution
operation. Learn from other mistakes made in the language, and pick
something else!
A habit I picked up from C++ (and source documentation tools with a C++
heritage) was to use `::` to separate module name from module identifier
in documentation. I have moved away from this in the last year or two
(i.e. I do not recommend this token either) because, similarly, `::`
itself already has several uses in the language, most of which have
something to do with "declaring" things, which hasn't got much to do
with namespace resolution.
As long as the syntax isn't a confusing overload of something existing I
really don't care what you choose, but simply as an example of unique
alternatives my current pick for documentation is a new token of `%%`.
You seek technical reasons above - I know my own personal Fortran
semantic analysis code would need substantial revision to deal with
overloading `( )` for namespace resolution, or (to a lesser extent)
overloading `%`. Compared with an alternative of some other unique
token, the overload options represent all cost and no benefit to me.
> In the absence of a built-in facility in the language to deal with
> non-unique enum values, the coder is forced to do so by modifying the
> enum value (e.g., add a particular prefix to the name) which is
> totally unnecessary in this day and age.
Only if the identifiers for the enumerator are initially declared in the
same scope (and declaring conflicting enumerator identifiers in the same
scope seems like a silly thing to want to do). If the conflict occurs
where one of the identifiers introduced through use association, then
the existing built-in facility of renaming in the use statement can be used.
> Some of my code works at the interface between engineering, science,
> and math and some terms such as ELEMENT, FACTOR, NODE, NORMAL, UNIT
> have different meanings in different contexts, they will be enum
> values, and I will indeed have non-unique enum values in the same
> scope. As I indicated earlier, Ada to C++, C# to Java, Python to
> Visual Basic easily provide facilities to coders to handle such
> situations. I think it's high time Fortran did too.
That situation is not limited to the identifiers for enumerators though.
This is another reason why I do not think a proposal for additional
support for enumerations should be bundled so tightly with this new
namespace concept. They are fundamentally two different animals.
Solely to contrast, because I think the merits of additional namespace
facilities in Fortran may be marginal, if you want additional namespace
facilities, then why not explicitly bring them in. Perhaps something like:
MODULE my_module
IMPLICIT NONE
INTEGER, PARAMETER :: another_constant = 2
NAMESPACE my_namespace
! Public entities of some_other_module accessible through
! this namespace.
USE some_other_module
! Host association of another_constant into this scope.
INTEGER, PARAMETER :: some_constant = another_constant
! perhaps here a declaration for some_enumeration,
! whatever form that might take.
TYPE :: some_type
...
END TYPE some_type
INTERFACE some_generic
PROCEDURE some_procedure
END INTERFACE some_generic
NAMESPACE child_namespace
! Go forth and nest...
END NAMESPACE child_namespace
END NAMESPACE my_namespace
! Qualification required out of the namespace construct.
TYPE(my_namespace%%my_type) :: some_variable
CONTAINS
! For specific procedures, perhaps we have to qualify the
! name, or perhaps the NAMESPACE construct has a CONTAINS
! statement and a subprogram part, or whatever...
SUBROUTINE my_namespace%%some_procedure
END SUBROUTINE my_namespace%%some_procedure
END MODULE
! Namespace entities brought in along with all other
! module entities, but the namespace entities require
!
USE my_module
PRINT *, my_namespace%%some_constant
! Bring in entities in the namespace only, with
! qualification still required.
USE my_module, ONLY: my_namespace
PRINT *, my_namespace%%some_constant
! Bring in entities in the namespace, renaming
! the namespace
USE my_module, local_name => my_namespace
PRINT *, local_name%%some_constant
! Bring in entities from the given namespace only,
! qualification no longer required. (perhaps this
! is abuse of a USE statement, and some separate
! source construct should be devised to achieve
! this - also you may want to eliminate the need for
! qualification in situations where you are not
! acquiring the namespace through USE).
USE my_module%%my_namespace
PRINT *, some_constant
Because you have unique syntax for namespace qualification, I think it
may be possible to put namespace names in their own class in 16.3.1,
permitting a namespace name to be the same as another local identifier
for something other than a namespace in the same scope. But that is the
sort of thing that would require careful consideration, as would the
impact of being able to eliminate the need for qualification in other
scopes.
> So is the Fortran committee going to view the matter similarly as
> this other post should they consider this aspect again, that they
> will only imagine ghosts and dragons lurking around every corner, and
> seek to include a 'lean', perhaps a watered down version compared to
> those in other competing languages (even Ada 95) which will be a
> marginal improvement over the utterly useless facility in the current
> standard and which will be of little service to coders like me? That
> would hardly be 'modern'.
One aspect to note is that it is difficult to eliminate the possibility
of ghosts and dragons until you have a more detailed proposal.
Recent language history also shows that sometimes when people try and
actually implement new language features in Fortran processors, dragons
do emerge.