# Comparison of programming languages (array)

This comparison of programming languages (array) compares the features of array data structures or matrix processing for various computer programming languages.

## Syntax
### Array dimensions

The following list contains syntax examples of how to determine the dimensions (index of the first element, the last element or the size in elements).
Some languages index from zero. Some index from one. Some carry no such restriction, or even allow indexing by any enumerated type, not only integers.
| Languages | Size | First | Last |
| Ada | name'Length | name'First | name'Last |
| ALGOL 68 | UPB name - LWB name+1 2 UPB name - 2 LWB name+1 etc. | LWB name 2 LWB name etc. | UPB name 2 UPB name etc. |
| APL | ⍴ name (⍴ name)[index] | ⎕IO | (⍴ name)-~⎕IO (⍴ name)[index]-~⎕IO |
| AWK | length | 1 | asorti |
| C#, Visual Basic (.NET), Windows PowerShell, F# | name.Length | name.GetLowerBound(dimension) | name.GetUpperBound(dimension) |
| CFML | arrayLen(name) name.len | 1 | name.len |
| Ch | max(shape(name)) | 0 | max(shape(name))-1 |
| Common Lisp | (length name) | 0 | (1- (length name)) |
| D | name.length | 0 | name.length-1 $-1 |
| Fortran | size(name) | lbound(name) | ubound(name) |
| Go | len(name) | 0 | len(name) - 1 |
| Haskell | rangeSize (bounds name) | fst (bounds name) | snd (bounds name) |
| ISLISP | (length name) | 0 | (1- (length name)) |
| Icon | *name | 1 | *name |
| Cobra, D, Haxe, Java, JavaScript, Scala | name.length | 0 | name.length - 1 |
| J | #name | 0 | <:@#name |
| JavaScript (ES2022) | name.length | 0 name.at(0) | name.length - 1 name.at(-1) |
| Julia | length(name) size(name) | begin first.(axes(name)) | end last.(axes(name)) |
| Lingo | count(name) | 1 | getLast(name) |
| LiveCode | length(name) | 1 first | -1 last |
| Lua | #name | 1 by convention; any integer | #name |
| Mathematica | Length[name] | 1 First[name] | -1 Last[name] |
| MATLAB, GNU Octave | length(name) | 1 | end |
| Nim | name.len | name.low | name.high |
| Oberon | LEN(name) | 0 | LEN(name) - 1 |
| Object Pascal | Length(name) | 0 low(name) | Length(name)-1 high(name) |
| Objective-C (NSArray * only) | [name count] | 0 | [name count] - 1 |
| OCaml | Array.length name | 0 | Array.length name - 1 |
| Perl | scalar(@name) | $[ | $#name |
| PHP | count(name) | 0 | count(name) - 1 |
| PL/I | dim(name[,dim]) | lbound(name[,dim]) | hbound(name[,dim]) |
| Python | len(name) | 0 | -1 len(name) - 1 |
| R | length(name) | 1 | length(name) |
| Raku | @name.elems | 0 | @name.end |
| Red | length? name | name/1 first name | last name |
| Ruby | name.size | 0 name.first | -1 name.size - 1 name.last |
| Rust | name.len | 0 | name.len - 1 |
| S-Lang | length(name) | 0 | -1 length(name)-1 |
| Scheme | (vector-length vector) | 0 | (- (vector-length vector) 1) |
| Smalltalk | name size | 1 name first | name size name last |
| Swift | name.count | 0 | name.count - 1 |
| Unicon | *name | 1 | *name |
| Visual Basic | UBound(name)-LBound(name)+1 | LBound(name) | UBound(name) |
| Wolfram Language | Length[name] | 1 First[name] | -1 Last[name] |
| Xojo | UBound(name) | 0 | UBound(name) |
| XPath/XQuery | count($name) | 1 | count($name) last array:size(name) |

### Indexing

The following list contains syntax examples of how to access a single element of an array.
| Format | Languages |
| name[index] or name[index$_1$, index$_2$] etc. | ALGOL 58, ALGOL 60, ALGOL 68, AWK, Julia, Modula, Pascal, Object Pascal, C#, S-Lang Icon, Unicon |
| name[index] or name[index$_1$; index$_2$] etc. or index⌷name or index$_1$ index$_2$⌷name etc. | APL |
| name[index] | ActionScript, C, CFML, Ch, Cobra, C++, D, Go, Haxe, Java, JavaScript, Lingo, Lua, Nim, Objective-C (NSArray *), Perl, PHP, Python, R, Ruby, Rust, Swift |
| $name[index] | Perl, Windows PowerShell, XPath/XQuery |
| @name[index] | Raku |
| name(index) or name(index$_1$, index$_2$) etc. | Ada, ALGOL W, BASIC, COBOL, Fortran, RPG, GNU Octave, MATLAB, PL/I, Scala, Visual Basic, Visual Basic (.NET), Xojo |
| $name(index) | XPath/XQuery |
| name.(index) | OCaml |
| name.[index] | F#, OCaml |
| name/index | Red |
| name ! index | Haskell |
| $name ? index | XPath/XQuery |
| (vector-ref name index) | Scheme |
| (aref name index) | Common Lisp |
| (elt name index) | ISLISP |
| name[[index]] | Mathematica, Wolfram Language |
| name at:index | Smalltalk |
| [name objectAtIndex:index] | Objective-C (NSArray * only) |
| index{name | J |
| name.item(index) or name @ index | Eiffel |

### Slicing

The following list contains syntax examples of how a range of element of an array can be accessed.
In the following table:
* first – the index of the first element in the slice
* last – the index of the last element in the slice
* end – one more than the index of last element in the slice
* len – the length of the slice (= end - first)
* step – the number of array elements in each (default 1)
| Format | Languages |
| name[first:last] | ALGOL 68, Julia, Icon, Unicon |
| name[first+(⍳len)-⎕IO] | APL |
| name[first:end:step] | Python |
| name[first:end] | Go |
| name[first..last] | Pascal, Object Pascal, Delphi, Nim |
| $name[first..last] | Windows PowerShell |
| @name[first..last] | Perl |
| name[first..last] name[first...end] name[first, len] | Ruby |
| copy/part skip name first len | Red |
| name(first..last) | Ada |
| name(first:last) | Fortran, GNU Octave, MATLAB |
| name[[first;;last;;step]] | Mathematica, Wolfram Language |
| name[[first:last]] | S-Lang |
| name.[first..step..last] | F# |
| name.slice(first, end) | Haxe, JavaScript, Scala |
| name.slice(first, len) | CFML |
| array_slice(name, first, len) | PHP |
| (subseq name first end) | Common Lisp |
| (subseq name first end) | ISLISP |
| Array.sub name first len | OCaml |
| [name subarrayWithRange:NSMakeRange(first, len)] | Objective-C (NSArray * only) |
| (first([+i.@(-~)end){name | J |
| name[first..<end] name[first...last] | Swift |
| name copyFrom: first to:last name copyFrom: first count:len | Smalltalk |
| name[first..end] | D, C# |
| name[first..end] name[first..=last] | Rust |
| name[first:end] | Cobra |
| table.move(name, first, last, 1,) | Lua |

## Array system cross-reference list

| Language | Default base index | Specifiable index type | Specifiable base index | Bound check | Multidimensional | Dynamically-sized | Vectorized operations |
| Ada | index type | yes | yes | checked | yes | init | some, others definable |
| ALGOL 68 | 1 | no | yes | varies | yes | yes | user definable |
| APL | 1 | ? | 0 or 1 | checked | yes | yes | yes |
| AWK | 1 | yes, implicitly | no | unchecked | yes, as delimited string | yes, rehashed | no |
| BASIC | 0 | ? | no | checked | no | init | ? |
| C | 0 | no | no | unchecked | partially | init, heap | no |
| Ch | 0 | no | no | checked | yes, also array of array | init, heap | yes |
| C++ | 0 | no | no | unchecked | yes, also array of array | heap | no |
| C# | 0 | no | partial | checked | yes | heap | yes (LINQ select) |
| CFML | 1 | no | no | checked | yes, also array of array | yes | no |
| COBOL | 1 | no | no | checked | array of array | no | some intrinsics |
| Cobra | 0 | no | no | checked | array of array | heap | ? |
| Common Lisp | 0 | ? | no | checked | yes | yes | yes (map or map-into) |
| D | 0 | yes | no | varies | yes | yes | ? |
| F# | 0 | no | partial | checked | yes | heap | yes (map) |
| FreeBASIC | 0 | no | yes | checked | yes | init, init | ? |
| Fortran | 1 | yes | yes | varies | yes | yes | yes |
| FoxPro | 1 | ? | no | checked | yes | yes | ? |
| Go | 0 | no | no | checked | array of array | no | no |
| Hack | 0 | yes | yes | checked | yes | yes | yes |
| Haskell | 0 | yes | yes | checked | yes, also array of array | init | ? |
| IDL | 0 | ? | no | checked | yes | yes | yes |
| ISLISP | 0 | ? | no | checked | yes | init | yes (map or map-into) |
| J | 0 | ? | no | checked | yes | yes | yes |
| Java | 0 | no | no | checked | array of array | init | ? |
| JavaScript | 0 | no | no | checked | array of array | yes | yes |
| Julia | 1 | yes | yes | checked (can be skipped locally; or globally by user) | yes, also array of array | yes | yes |
| Lingo | 1 | ? | ? | unchecked | yes | yes | yes |
| Lua | 1 | ? | partial | checked | array of array | yes | ? |
| Mathematica | 1 | no | no | checked | yes | yes | yes |
| MATLAB | 1 | ? | no | checked | yes | yes | yes |
| Nim | 0 | yes | yes | optional | array of array | yes | yes |
| Oberon | 0 | ? | no | checked | yes | no | ? |
| Oberon-2 | 0 | ? | no | checked | yes | yes | ? |
| Objective-C | 0 | no | no | checked | array of array | yes | no |
| OCaml | 0 | no | no | checked by default | array of array | init | ? |
| Pascal, Object Pascal | index type | yes | yes | varies | yes | varies | some |
| Perl | 0 | no | yes ($ | checked | array of array | yes | no |
| Raku | 0 | no | no | checked | yes | yes | yes |
| PHP | 0 | yes | yes | checked | yes | yes | yes |
| PL/I | 1 | yes | yes | optional | yes | no | yes |
| Python | 0 | no | no | checked | array of array | yes | no |
| RPG | 1 | no | no | ? | no | no | ? |
| R | 1 | ? | no | unchecked | yes, also array of array | yes | yes |
| Ring | 1 | ? | partial | checked | array of array | yes | ? |
| Ruby | 0 | no | no | checked | array of array | yes | ? |
| Rust | 0 | no | no | checked | array of array | no | ? |
| Sass | 1 | no | no | checked | array of array | init | ? |
| S-Lang | 0 | ? | no | checked | yes | yes | yes |
| Scala | 0 | no | no | checked | array of array | init | yes (map) |
| Scheme | 0 | ? | no | checked | array of array | init | yes (map) |
| Smalltalk | 1 | ? | no | checked | array of array | yes | ? |
| Swift | 0 | no | no | checked | array of array | yes | ? |
| Visual Basic (classic) | 0, 1, or index type | no | yes | checked | yes | yes | ? |
| Visual Basic (.NET) | 0 or index type | no | partial | checked | yes | yes | yes (LINQ select) |
| Wolfram Language | 1 | no | no | checked | yes | yes | yes |
| Windows PowerShell | 0 | no | no | checked | yes | heap | ? |
| Xojo | 0 | no | no | checked | yes | yes | no |
| XPath/XQuery | 1 | no | no | checked | array of array | yes | yes |

## Vectorized array operations

Some compiled languages such as Ada and Fortran, and some scripting languages such as IDL, MATLAB, and S-Lang, have native support for vectorized operations on arrays. For example, to perform an element by element sum of two arrays, a and b to produce a third c, it is only necessary to write
In addition to support for vectorized arithmetic and relational operations, these languages also vectorize common mathematical functions such as sine. For example, if x is an array, then
will result in an array y whose elements are sine of the corresponding elements of the array x.
Vectorized index operations are also supported. As an example,
is how one would use Fortran to create arrays from the even and odd entries of an array. Another common use of vectorized indices is a filtering operation. Consider a clipping operation of a sine wave where amplitudes larger than 0.5 are to be set to 0.5. Using S-Lang, this can be done by

### Mathematical matrix operations

| Language/ Library | Create | Determinant | Transpose | Element | Column | Row | Eigenvalues |
| APL | m←dims⍴x11 x12 ... | -.×m | ⍉m | m[i;j] or i j⌷m | m[;j] or j⌷[2]m or j⌷⍤1⊢m or j⌷⍉m | m[i;] or i⌷m | ⌹⍠1⊢m |
| Fortran | m = RESHAPE([x11, x12, ...], SHAPE(m)) | | TRANSPOSE(m) | m(i,j) | m(:,j) | m(i,:) | |
| Ch | m = {...} | determinant(m) | transpose(m) | m[i-1][j-1] | shape(m,0) | shape(m,1) | eigen(output, m, NULL) |
| Julia and its standard library LinearAlgebra | m = [1 2; 3 4] or m = [ 1 2 3 4 ] | det(m) | transpose(m) or m' for real matrices | m[i, j] | m[:, j] | m[i, :] | eigen(m).values |
| Mathematica / Wolfram Language | {{x11, x12, ...}, ...} | Det[m] | Transpose[m] | m[[i,j]] | m[[;;,j]] | m[[i]] | Eigenvalues[m] |
| MATLAB / GNU Octave | m = [...] | det(m) | m.' | m(i,j) | m(:,j) | m(i,:) | eig(m) |
| NumPy | m = mat(...) | linalg.det(m) | m.T | m[i-1,j-1] | m[:,j-1] | m[i-1,:] | linalg.eigvals(m) |
| R | m <- matrix(...) or m <- array(...) | det(m) | t(m) | m[i, j] | m[, j] | m[i, ] | eigen(m) |
| S-Lang | m = reshape([x11, x12, ...], [new-dims]) | | m = transpose(m) | m[i,j] | m[*,j] | m[j,*] | |
| SymPy | m = Matrix(...) | m.det | m.T | m[i-1,j-1] | m.col(j-1) | m.row(i-1) | m.eigenvals |