Clifton_RL@admdev.cut.oz (03/03/90)
IMPLIED DO-LOOP STATEMENT Currently, Fortran requires the first character in a statement to be alpha. If we allowed an open-bracket character "(" we could use the implied do-loop construction. For example: (((C(I,J)=A(I,K)*B(K,J) ,K=1,M) ,I=1,M) ,J=1,M) This clear statement would replace the familiar clutter of: DO J etc DO I etc DO K etc C(I,J)= etc ENDDO ENDDO ENDDO -plus blank lines an apologetic explanation... How about it?
maine@elxsi.dfrf.nasa.gov (Richard Maine) (03/05/90)
On 3 Mar 90 03:06:41 GMT, Clifton_RL@admdev.cut.oz said: Clifton> IMPLIED DO-LOOP STATEMENT Clifton> We could use the implied do-loop construction. For example: Clifton> (((C(I,J)=A(I,K)*B(K,J) ,K=1,M) ,I=1,M) ,J=1,M) Clifton> This clear statement would replace the familiar clutter of: Clifton> DO J etc Clifton> DO I etc Clifton> DO K etc Clifton> C(I,J)= etc Clifton> ENDDO Clifton> ENDDO Clifton> ENDDO Clifton> How about it? Its mostly just a matter of taste (which means others are sure to disagree), but I find the DO-ENDDO to be clearer than the implied DO construct you show. Longer, true, but I wouldn't call it cluttered. Perhaps it's just because I'm used to it. The real test comes when things get more complicated. You showed just about the simplest possible do loop. How about when you replace the inner core with something with multiple statements - perhaps a block if (or even something with statement labels and G*TO statements :-)). Or what happens when there are statements in some of the intermediate level DO's. Certainly you COULD write such things in an implied DO notation, but I think they will be very hard to read, particularly when the loop contents get large enough that the J=1,M or whatever is several lines below the first reference to the J. That would mean you could not read the code sequentially, but would have to scan ahead to figure out what this J thing was. Possible, but awkward. -- Richard Maine maine@elxsi.dfrf.nasa.gov [130.134.64.6]
jlg@lambda.UUCP (Jim Giles) (03/05/90)
From article <2044.25efa542@admdev.cut.oz>, by Clifton_RL@admdev.cut.oz: > IMPLIED DO-LOOP STATEMENT > [...] > (((C(I,J)=A(I,K)*B(K,J) ,K=1,M) ,I=1,M) ,J=1,M) You probably intended this to be: ((C(I,J)=0, I=1,M), J=1,M) (((C(I,J)=C(I,J)+A(I,K)*B(K,J), I=1,M), J=1,M), K=1,M) Your code just redefines each element of C M times. Further, the loop vectorizes better with the sum on the OUTER loop. Why not just overload the multiply operator on MATRIX type variables and say: C = A*B and declare A, B, and C as type MATRIX? J. Giles
chidsey@smoke.BRL.MIL (Irving Chidsey) (03/05/90)
In article <2044.25efa542@admdev.cut.oz> Clifton_RL@admdev.cut.oz writes:
<IMPLIED DO-LOOP STATEMENT
<
<Currently, Fortran requires the first character in a statement
<to be alpha. If we allowed an open-bracket character "(" we
<could use the implied do-loop construction. For example:
<
< (((C(I,J)=A(I,K)*B(K,J) ,K=1,M) ,I=1,M) ,J=1,M)
<
<This clear statement would replace the familiar clutter of:
<
< DO J etc
< DO I etc
< DO K etc
< C(I,J)= etc
< ENDDO
< ENDDO
< ENDDO
< -plus blank lines an apologetic explanation...
<
<
<How about it?
How about:
Do (((C(I,J)=A(I,K)*B(K,J),K=1,M),I=1,M),K=1,M)
Which would be similar to the implied do in IO statements.
An occasaional word helps the human reader as well as the compiler.
Irv
--
I do not have signature authority. I am not authorized to sign anything.
I am not authorized to commit the BRL, the DOA, the DOD, or the US Government
to anything, not even by implication.
Irving L. Chidsey <chidsey@brl.mil>
ghm@ccadfa.adfa.oz.au (Geoff Miller) (03/06/90)
In article <MAINE.90Mar4094233@altair.dfrf.nasa.gov> maine@elxsi.dfrf.nasa.gov (Richard Maine) writes: >On 3 Mar 90 03:06:41 GMT, Clifton_RL@admdev.cut.oz said: >Clifton> IMPLIED DO-LOOP STATEMENT >Clifton> We could use the implied do-loop construction. For example: >Clifton> (((C(I,J)=A(I,K)*B(K,J) ,K=1,M) ,I=1,M) ,J=1,M) >Clifton> This clear statement would replace the familiar clutter of.... > >Its mostly just a matter of taste (which means others are sure to >disagree), but I find the DO-ENDDO to be clearer than the implied >DO construct you show. Longer, true, but I wouldn't call it cluttered. >Perhaps it's just because I'm used to it. >...Certainly you COULD write such things in an implied DO >notation, but I think they will be very hard to read.... I must agree with Richard. It comes back to the old arguments about maintainable code vs compact code, and there are many occasions where a succession of simple statements is far more comprehensible, albeit longer, than the compact form. This is the case with the DO loops dicussed above, and also with the IF-ENDIF structure. Of course, if you really like compact code you can always write in APL.... Geoff Miller ghm@cc.adfa.oz.au
desj@idacrd.UUCP (David desJardins) (03/06/90)
From article <14259@lambda.UUCP>, by jlg@lambda.UUCP (Jim Giles): > Why not just overload > the multiply operator on MATRIX type variables and say: > > C = A*B > > and declare A, B, and C as type MATRIX? Because this is already meaningful and does pointwise multiplication. -- David desJardins
lamson@sierra.crd.ge.com (scott h lamson) (03/06/90)
In article <640@idacrd.UUCP> desj@idacrd.UUCP (David desJardins) writes: > From: desj@idacrd.UUCP (David desJardins) > From article <14259@lambda.UUCP>, by jlg@lambda.UUCP (Jim Giles): > > Why not just overload > > the multiply operator on MATRIX type variables and say: > > > > C = A*B > > > > and declare A, B, and C as type MATRIX? > Because this is already meaningful and does pointwise > multiplication. A * B is meaningful for ARRAYS as pointwise multiplication, but is not defined for the new derived type MATRIX unless you define it yourself or in a MODULE you are accessing. Of course, you do have to choose either pointwise multiplication or matrix multiplication. -- Scott| ARPA: lamson@crd.ge.com Lamson| UUCP: uunet!crd.ge.com!lamson (518)387-5795| UUCP: uunet!sierra.crd.ge.com!lamson