jlg@a.UUCP (Jim Giles) (03/11/88)
> The criterion for Fortran 8x features (in my opinion) should be to > certify existing practice or to extend the language in a significant > way. I will use this criterion throughout this discussion. The case statement fits both the above criteria to some extent. It provides functionality similar to computed GOTOs but more readibly. In particular, the cases don't fall through. The proposed syntax is similar to that seen in many preprocessors for Fortran and is nearly identical to the case construct in C. As I pointed out, the case statement functions similar to the most common use of computed GOTOs. But computed GOTOs should not be depricated unless the case construct is extended to allow fall-through and branches between the cases. These capabilities are not very structured, and shouldn't be the default behaviour of case, but they do provide a mechanism to speed-up a code and/or make the code more compact (and often more readable). There has been some comment about the cumbersome syntax of the case statement as it has been proposed. As I pointed out above, it is similar to what other implementations have already - both within Fortran and elsewhere. The basic argument is over an example such as: Fortran 8x vs. Dijkstra-like guarded sequences SELECT CASE (N) CASE (N) CASE (:-1); SIGNUM = -1 :-1 => SIGNUM = -1 CASE (0); SIGNUM = 0 0 => SIGNUM = 0 CASE (1:); SIGNUM = 1 1: => SIGNUM = 1 END SELECT END CASE Now, presumably, the Dijkstra-like syntax allows more than one statement in each branch of the case (Fortran 8x regards the CASE as a statement itself which marks the beginning and end of each sequence of statements for the branch). The problem with examples like this is that they look at the wrong end of the program-size spectrum. The REAL use of cases is like: Fortran 8x vs. Dijkstra-like guarded sequences SELECT CASE (BIG_EXPRESSION) CASE (BIG_EXPRESSION) CASE (EXPRESSION1:EXPRESSION2) EXPRESSION1:EXPRESSION2 => ... ... ABOUT A PAGE (OR MORE) OF CODE LOTS OF CODE ... ... CASE (EXPRESSION3:EXPRESSION4) EXPRESSION3:EXPRESSION4 => ... ... MORE PAGES OF CODE MORE CODE ... ... MORE CASES MORE CASES ... ... END SELECT END CASE In this example, the Fortran 8x version would be much more readable. The word CASE appears at the left margin of the code and is therefore more easily found when scanning the code than the imbedded arrow. With fixed source form, the problem is worse since more people are tempted to refrain from using any indentation conventions in their code. I think that for large codes the proposed syntax is about the best that can be expected. J. Giles Los Alamos