It is so quiet on the mailing that I thought some little proposal
might be worth seeing the day of light for a little discussion.
Fortran has a number of inconsistencies when it comes to declaring
various entities and a subset is the topic of this email.
Most of this subset should be easily improved by a few editorial
changes.
The following general principles should apply:
1. Any attribute that can effect data objects or procedures
or interfaces can be specified as an attribute-specification
in the declaration (and as a separate attribute-statement).
2. Any declaration statement can contain the optional "::"
Since the following only concerns the more modern notation
introduced in F90 only examples in that notation will be given.
The employed style is used to highlight the topic.
To 1(+2):
The current F90/95 rules allow the following declarations:
Real, PARAMETER :: a
Real, SAVE :: x
Real, TARGET, ALLOCATABLE :: x
! etc
! Declaring variables of some type
Type(atype), PARAMETER :: T
Type(atype), ALLOCATABLE :: S(3)
! Defining a TYPE
Type, PUBLIC :: atype
END Type atype
BUT the following declarations do not follow principle 1 for no apparent
reason, esp. the attributes PUBLIC and PRIVATE have to be specified in a
separate statement:
Real FUNCTION foo
END FUNCTION foo
PUBLIC :: foo
SUBROUTINE sub
END SUBROUTINE sub
PUBLIC :: sub
INTERFACE InF
END INTERFACE InF
PUBLIC :: InF
INTERFACE OPERATOR(.op.)
END INTERFACE OPERATOR(.op.)
PUBLIC :: OPERATOR(.op.)
! similarly ASSIGNMENT
I suggest that the language allows the syntax of the following examples
as well:
Real, FUNCTION, PUBLIC :: foo
END FUNCTION foo
! some additional attributes are allowed for FUNCTION
! like RECURSIVE, PURE, ...
SUBROUTINE, PUBLIC :: sub
END SUBROUTINE sub
INTERFACE, PUBLIC :: if
END INTERFACE if
INTERFACE, PUBLIC :: OPERATOR(.op.)
END INTERFACE OPERATOR(.op.)
! similarly ASSIGNMENT
This would result in the following very regular declarations:
Real, PARAMETER, PUBLIC :: a
Real, [variable,] PUBLIC :: x
Real, FUNCTION, PUBLIC :: foo()
The "variable" is only introduced to highlight the regularity, it
is not suggested as a new attribute.
This also shows that the attributes are not all of the same quality,
PARAMETER, FUNCTION, SUBROUTINE belong into one group as they are
mutually exclusive, etc.
The general declaration (only F90 style) can hence be specified
along the lines:
[type-spec,]
[PARAMETER or FUNCTION or SUBROUTINE or INTERFACE,]
[other attribute-spec] ::
name [(arguments) [RESULT clause] or initial expression]
To 2:
A few examples will suffice, more have been given in 1.
Examples:
MODULE :: A
END MODULE A
USE :: A, ONLY: x, y
PROGRAM :: Test
END PROGRAM Test
This principle is suggested as it is a natural consequence of 1, esp.
the extended TYPE, FUNCTION, SUBROUTINE, INTERFACE declarations.
The proposed syntax is easy to remember and allows the easy addition
of attributes.
The new notation certainly keeps data objects, procedures etc and their
attributes closely together, thereby enhancing readability of code
and a more regular and easier syntax.
For example with the new USE notation we could write
MODULE :: A
PRIVATE
USE, PUBLIC :: B
USE, PUBLIC :: C, ONLY: C_1, C_2
!etc.
END MODULE A
where all entities of MODULE B are also visible when module A is USEd
elsewhere. This gives much better control over visibility than with
the current syntax rules.
Module C is qualified with an ONLY list, and only the metioned members
are visible when module A is USEd. One could even have two USE statements
of C where a qualified USE (ie. with ONLY) overrides the general USE
form:
USE, PRIVATE :: C
USE, PUBLIC :: C, ONLY: C_1, C_2
But that is maybe going too far.
Most important and I think easily achievable and not conflicting with
current programmes is to allow the PUBLIC|PRIVATE statements in an
attribute list for ALL declarations as under 1.)
Cheers,
WWS
-----------------------------------------------------------------------
| Werner W Schulz |
| Dept of Chemistry email: [log in to unmask] |
| University of Cambridge Phone: (+44) (0)1223 336 502 |
| Lensfield Road Secretary: 1223 336 338 |
| Cambridge CB2 1EW Fax: 1223 336 536 |
| United Kingdom WWW: |
-----------------------------------------------------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|