[comp.lang.fortran] F8X: a call to action

hirchert@uxe.cso.uiuc.edu (02/17/88)

On the subject of the proposed Fortran 8x CASE construct
1. The suggested alternative syntax would probably fit well in a Pascal-like
   language with reserved words, significant blanks, etc.  I suspect it would
   be a nightmare to parse in the context of Fortran.
2. With the exception of the assignment statement and the statement function
   (which looks syntactically like an assignment statement), all statements
   in Fortran begin with a keyword.  Hence, the keyword CASE was used in the
   "case labels".
3. Many of the keywords used for executable statements are verbs.  Hence, the
   keyword SELECT was included in the initial statement.
4. Note that CASE DEFAULT is different from CASE(DEFAULT).  The latter is
   for a case identified by a symbolic constant named DEFAULT.  The suggested
   alternative syntax does not make this distinction.
5. When the actions involve only a single statement, the new source form
   can be used to readably reduce the number of lines involved:
     SELECT CASE(N)
      CASE(:-1);SIGNUM=-1
      CASE(0);  SIGNUM=0
      CASE(1:); SIGNUM=1
     END SELECT

In answer to the question about how this compares to the C switch statement,
this construct guarantees that only a single CASE block will be executed.
In other words, it is like switch with all the necessary break statements
included.  In still other words, it is like a Pascal case statement (but with
a default case capability that is a nonstandard Pascal extension).

Kurt W. Hirchert    National Center for Supercomputing Applications

corbett@beatnix.UUCP (Bob Corbett) (02/19/88)

In article <50500028@uxe.cso.uiuc.edu> hirchert@uxe.cso.uiuc.edu writes:
>On the subject of the proposed Fortran 8x CASE construct
>1. The suggested alternative syntax would probably fit well in a Pascal-like
>   language with reserved words, significant blanks, etc.  I suspect it would
>   be a nightmare to parse in the context of Fortran.

My proposed syntax would be easy to parse.  The character pair `->' (arrow)
is currently illegal outside of strings and Hollerith.  Therefore, when the
compiler classifies statements, it will just look for arrow in addition to
all the other forms it already identifies.  If the arrow is found, it passes
a hint to the parser to look for expression syntax until the arrow is
reached.

>2. With the exception of the assignment statement and the statement function
>   (which looks syntactically like an assignment statement), all statements
>   in Fortran begin with a keyword.  Hence, the keyword CASE was used in the
>   "case labels".

I assume you will use this argument to oppose if-construct-names,
do-construct-names, and case-construct-names in you response to the public
review of FORTRAN 8X.

>3. Many of the keywords used for executable statements are verbs.  Hence, the
>   keyword SELECT was included in the initial statement.

Verbs like IF (:-).

>4. Note that CASE DEFAULT is different from CASE(DEFAULT).  The latter is
>   for a case identified by a symbolic constant named DEFAULT.  The suggested
>   alternative syntax does not make this distinction.

You are correct.  The simplest fix would be to let empty text to the left of
the arrow signify the default case.  The resulting construct would be more
concise than my original proposal but less readable.

>5. When the actions involve only a single statement, the new source form
>   can be used to readably reduce the number of lines involved:
>     SELECT CASE(N)
>      CASE(:-1);SIGNUM=-1
>      CASE(0);  SIGNUM=0
>      CASE(1:); SIGNUM=1
>     END SELECT

Given this paradigm of readability, how can I continue to oppose the current
CASE syntax?  (Ans: easily)

>In answer to the question about how this compares to the C switch statement,
>this construct guarantees that only a single CASE block will be executed.
>In other words, it is like switch with all the necessary break statements
>included.  In still other words, it is like a Pascal case statement (but with
>a default case capability that is a nonstandard Pascal extension).
>
>Kurt W. Hirchert    National Center for Supercomputing Applications

Let me reiterate that I am not suggesting that my alternate form of the CASE
statement should be adopted in FORTRAN 8X.  I presented it to demonstrate that
it is possible to do better than the current CASE syntax.  I hope that the
CASE contruct finally adopted in FORTRAN 8X will be better than either
proposal.

						Sincerely,
						Robert Paul Corbett