Jump to content

Array programming

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Danakil (talk | contribs) at 19:33, 10 August 2004 (also known as 'vector' or 'multidimensional' langs). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

Array programming languages (also known as vector or multidimensional languages) generalize operations on scalars to apply transparently to vectors, matrices, and higher dimensional arrays.

Overview

In scalar languages like Fortran, C, Pascal, Ada, etc. operations apply only to single values, so a+b expresses the addition of two numbers. In such languages adding two arrays requires indexing and looping:

FORTRAN 77

   DO 10 I = 1, N
     DO 10 J = 1, N
10       A(I,J) = A(I,J) + B(I,J)


C

     for ( i=0; i<n; i++) {
         for ( j=0; j<n; j++) {
             a[i][j] = a[i][j]+b[i][j];
         }
     }

This need to loop and index to perform operations on arrays is both tedious and error prone.

In array languages, operations are generalized to apply to both scalars and arrays. Thus, a+b expresses the sum of two scalars if a and b are scalars, or the sum of two arrays if they are arrays. When applied to arrays, the operations act on corresponding elements as illustrated in the loops above. Indeed, when the an array language compiler/interpreter encounters an statement like:

A := A + B

and A and B are two dimensional arrays, it generates code that is effectively the same as the C loops shown above. An array language, therefore, simplifies programming.

Examples

Some examples of array programming languages:

APL programming language
J programming language
NGL programming language
ZPL programming language
NESL programming language
NIAL programming language