Oberon vs F-90 
Author Message
 Oberon vs F-90

Quote:
>|> Concerning storage of arrays in various languages, it should be clear to
>|> anyone with half a brain (or with a linear algebra course 101 in their
>|> transcript, whichever ;-) that fortran did it the right way.
>I don't understand this comment. In my experience, when a
>mathematician writes

>                     A
>                      ij

>he means the element of A at row i, column j,
>which seems quite a lot like row-major ordering
>to me.

I think that the deal is that in memory the stuff is stored linearly.
This means that multi-dimensional arrays are actually linear arrays
of pointers (or equivelent links).  For example:

| 1 2|  in reality becomes       0000    ^0010   (* pointer *)
| 3 4|                           0001    ^0100   (* pointer *)
                                 0010    1       (* integer *)
                                 0011    2       (* integer *)
                                 0100    3       (* integer *)
                                 0101    4       (* integer *)
                                 0111
                                 1000

So to access A 1,1 the computer goes to where the pointer for row 1
is, gets the location for where row one is actually stored, goes to
that location, then advances (j - 1) locations to get the value of
A 1,1.

That's what I put together by row major arrays.  I don't know Fortran
from my elbow, so how it stores arrays I don't know, but it seems to
be different.  I gather such from the discussions.

Mick Powers

p.s. Amusing side note: my father does teach Fortran at the community
college.  He always tells the class at the beginning what Fortran means
(where the identifier came from), asks them on the first exam, and most
usually get it wrong.  Sigh.



Wed, 04 Jun 1997 03:32:51 GMT  
 Oberon vs F-90

: >|> Concerning storage of arrays in various languages, it should be clear to
: >|> anyone with half a brain (or with a linear algebra course 101 in their
: >|> transcript, whichever ;-) that Fortran did it the right way.
: >I don't understand this comment. In my experience, when a
: >mathematician writes
: >
: >                     A
: >                      ij
: >
: >he means the element of A at row i, column j,
: >which seems quite a lot like row-major ordering
: >to me.

: I think that the deal is that in memory the stuff is stored linearly.
: This means that multi-dimensional arrays are actually linear arrays
: of pointers (or equivelent links).  For example:

Nope. Most Fortan and Pascal-like languages use a single block
of contiguous storage. The difference is how they are indexed.

The difference between Pascal-like languages ( Pascal/Modula/Oberon )
and FORTRAN matrix notation is that pascal-like languages follows from
the design of the recursive data types whereas Fortran follows common
mathematical notation.

In Pascal-like languages array ("[","]" ), record field (".")
and pointer selectors ("^" ) follow a simple left to right ordering
that mirrors the type definition regardless whether or not

Eg.
   a : ARRAY N OF BaseType;

used as
   a[4]

If the base type is a record then

   a : ARRAY N OF
        RECORD
           x : FieldType
        END;
used as
   a[2].x

If the field of a record is an array then array selectors follows the
record selector as expected.

    a : ARRAY N OF
          RECORD
                x : ARRAY M OF REAL;
          END;

    a[2].x[3] := 6.0;

Of course this leads to the problem that Pascal-like languages
do not follow the usual mathematical notation.

        a : ARRAY N OF ARRAY M OF REAL;
or      a : ARRAY N,M OF REAL; (* MxN array *)

        a[j][i] := 5.0;
or      a[j,i] := 5.0;

Older FORTRAN's did not have records and pointers. ( This meant of
course that there was no convienent way to build trees and other
common computer/numerics data structures. But that is another storey.
Perhaps some old FORTRAN programmer will be happy to tell you how they
mapped out the nodes of a tree from a single block of memory on
a IBM/360, 486DX266 or some similar relic iron of days gone by  :-) ).
What fortran had was arrays and simple data types. Arrays were defined
and indexed a notation that closely follows common the matrix notation
of most math texts. The compiler writer was leveled with the
responsibility of the less systematic notation.

        DEFINE a[M,N]
        a[i,j] = 5.0

Note : although the Pascal and FORTRAN notations appear different
they are in fact indexing the same memory cells.

In either case programmers walk/index softly along the so-called
cache-lines and vary the index that follows the cache line more
frequently than the one that is perpendicular to the cache line.

Whitney



Wed, 04 Jun 1997 13:40:17 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Oberon vs F-90

2. Oberon vs F-90

3. Return Receipt: Re: Oberon vs F-90

4. Oberon vs F-90 and my two questions

5. Oberon vs F-90

6. Oberon vs F-90

7. FS: Fortran 90 compilers for Windows 95/NT

8. Fortran 90 vs HPF vs Fortran D

9. Fortran 77 vs Fortran 90/95

10. fortran77 vs fortran 90 or 95

11. fortran 90/95 pointers vs C pointers

12. FORTRAN 90 : Public vs. Private

 

 
Powered by phpBB® Forum Software