I'm posting this to comp.lang.fortran and sending it to comp-fortran-90
since there are some folks who read one or the other but not both.
Parentheses are used for a lot of things in Fortran:
o array indices
o argument lists of routines
o in the normal mathematical sense, e.g. A*(B+C) as shorthand for
A*B+A*C
o to force the compiler to evaluate the expression in parentheses
first, for example to avoid overflow or underflow
There was some talk here or on the comp-fortran-90 list recently about
the "confusion" of the last two points. Of course, the compiler ALWAYS
MUST evaluate parentheses first (or at least its results must be as if
it did this---not sure of the legalese here) (otherwise it is free to
transform an expression into something mathematically (but not
necessarily numerically) equivalent), but sometimes this is as a result
of the way a statement is written in "mathematical shorthand" and
sometimes because the programmer wants some sub-expression evaluated
first, for numerical reasons.
The last two cases are actually quite different.
What do folks think of using [] or {} (which are not part of the Fortran
character set at present) to replace parentheses in cases where the
programmer wants to tell the compiler "these parentheses are here so I
can write in `mathematical shorthand'; you are free to convert the
expression into something else which is mathematically equivalent and do
not have to evaluate the expression in parentheses first"?
If you don't want it, don't use it. The present behaviour of () would
remain. When you read code, just replace [] or {} with () in your mind
(or your editor) and it can be all the same to you. It is completely
backward-compatible.
Is there a need for this?
Certainly there are times when one would like to write something in a
mathematically straightforward way, but where the grouping caused by the
parentheses perhaps slows the code down. Anything using temporary
variables etc to fix this by hand makes for less readable code; using []
or {} would be just as readable as present code. Perhaps a compiler
could even reform the expression to avoid overflow or underflow etc.
Phillip Helbig
--
Kapteyn Instituut Email .............. [log in to unmask]
Rijksuniversiteit Groningen Tel. ................... +31 50 363 4067
Postbus 800 Fax .................... +31 50 363 6100
NL-9700 AV Groningen Web ... http://www.astro.rug.nl/~helbig/
******************************** formerly at ********************************
this will still work for a while -----> Email ......... [log in to unmask]
University of Manchester Tel. ... +44 1477 571 321 (ext. 2635)
Jodrell Bank Observatory Fax ................ +44 1477 571 618
Macclesfield Telex ................ 36149 JODREL G
UK-Cheshire SK11 9DL Web ... http://www.jb.man.ac.uk/~pjh/
My opinions are not necessarily those of either of the above institutes.
<A HREF=" http://gladia.astro.rug.nl:8000/helbig/hire/hire.html ">HIRE ME!</A>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|