Phrase reversals: Difference between revisions

m
Line 621:
 
=={{header|Fortran}}==
The key here is the ability via F90 to specify an array span, as A(''first'':''last'':''step'') where the ''step'' can be negative... This facility is not available for CHARACTER variables where only TEXT(''first'':''last'') is available - no ''step'' is accommodated and TEXT(''last'':''first'') evokes nothing rather than a backwards order as in Python. However, one can have an array of CHARACTER*1 variables, and as an array they can be rolled bidirectionally. For convenience in initialising such an array, EQUIVALENCE(TEXT,ATXT) means that a normal multi-character text literal can be assigned to TEXT via the DATA statement, rather than having to specify the ATXT elements one at a time.
 
By identifying the first and last character position of each word in TEXT (or equivalently, their indices in ATXT) and storing them in arrays IST and LST, the i'th word can be fingered via IST(i) to LST(i) and of course a DO-loop can step in either direction.
1,220

edits