Re: Array Constructors



Jan Vorbrüggen wrote:

Also note that I/O-implied DO variables are different. They do not have
their own scope, but are "ordinary" variables. There was once a time
when I was unaware of this distinction myself (and thus made a fool of
myself vehemently explaining something that turned out to be wrong. Oh
well. It happens).

Is there any good reason for this, apart from "this is how the vote went" (if anybody ever noticed before it was too late" or "we put it in so that Richard Maine would have a chance to make a fool of himself" 8-)? I can't see a technical need for two of the implied-do-variable types to behave one way and the third in another.

Because they are different. Note, first, the I/O implied DO goes back
to Fortran I, when 32K was a lot of memory. As Richard says, I go
to implementation too soon, but it is easier to see that way.
Implementations are allowed to, and often do, use a real loop for
an I/O implied DO. For the simpler cases it is likely that loop is
internal to the I/O routine, but for more complicated cases it is
likely part of the I/O statement. Consider:

READ(*,*) J,(A(INT(SQRT(REAL(I)))),I=1,J)

at least through the Fortran 66 days, and likely through Fortran 77
it was reasonable to allow I to be a normal variable.

For DATA statements which initialize data, and are not executable
statements, if there is an actual variable it is used before the
program execution begins. (Some would say compile time, and that
is likely the usual implementation.) It is a little less obvious for
array constructors, but if you consider it as an array constant,
similar to an array initialized in a DATA statement before execution
begins, it makes more sense.

For array constructors, it isn't so obvious. I am not sure about
something like:

write(*,"(8I5)") j,(/(XYZ(i),i=1,j)/)

Though in the above the array can be constructed before execution
of the WRITE begins. I don't believe that you can do:

read(*,"(8I5)") j,(/(XYZ(i),i=1,j)/)

so it seems that there are some differences between I/O implied
DO and array constructor implied DO.

-- glen

.


Quantcast