Re: New style DO syntax?
- From: Gordon Sande <g.sande@xxxxxxxxxxxxxxxx>
- Date: Tue, 25 Apr 2006 22:05:01 GMT
On 2006-04-25 18:31:09 -0300, Joe Krahn <lastname_at_niehs.nih.gov@xxxxx> said:
*** Hendrickson wrote:
Joe Krahn wrote:
Another simple idea for 'modern' Fortran Standards. It seems fairly obvious, so maybe it has already been proposed and rejected.
I think that the DO-loop is the only "block construct" that does not contain the 'expression/attribute' part in parenthesis. It also is the only one that does not have a statement form. I think it would be good to support a new DO syntax that also has a statement form. This would be much more consistent with all of the newer block constructs.
Using parenthesis for delimiters should also allow for using array elements as do iterators. (I am assuming that the reason they are not allowed is from the complexity of blank-insignificant fixed-format parsing, but there could be other issues.)
I'm not sure there is a parsing problem for something like
DO 10 A(I) = 1,10
that's any more difficult than the normal DO. The comma
outside of parenthesis after an = is the thing to look for.
I think the issue is what happens if "I" changes during the
loop? Which choice
1) Forbid I from changing
2) Capture the value of I at loop start and use that for
all the whole loop iterations
3) Use the current value of I whenever the iterator is
needed
is best?
Personally, I'd prefer doorway number 3. It looks like
it could give optimizers a whole new sandbox to play in. ;)
Seriously, when there are three reasonably plausible
interpretations of a syntax, it's probably not a good
idea to pick one unless there is a compelling need
for the feature. It just leads to human confusion.
*** Hendrickson
OK; that does bring up a more important issue with an array iterator. Maybe it would be worth supporting array variables only where the index is a constant. That is useful for something like:
do xyz(1)=1,nx
do xyz(2)=1,ny
do xyz(3)=1,nz
... something using vector xyz(:) ...
end do
end do
end do
Joe
The example seems contrived. You might as well equivalence the indices
to array elements so it would become contrived in the extreme.
The case where one would be tempted to use array elements as indices
are where there is to be a variable number of nested loops. I have done
it and have seem it asked for enough times that it should be a FAQ with
a moderate number. But you have no way of writing a variable number of lines
of source code so you still need to have the solution handy.
The question is often how to produce all the permutations of a variable
number of objects. The count gets big fast!
.
- References:
- New style DO syntax?
- From: Joe Krahn
- Re: New style DO syntax?
- From: *** Hendrickson
- Re: New style DO syntax?
- From: Joe Krahn
- New style DO syntax?
- Prev by Date: Re: New style DO syntax?
- Next by Date: Re: Compiling in 32 vs 64 platform problem
- Previous by thread: Re: New style DO syntax?
- Next by thread: Re: New style DO syntax?
- Index(es):