| Format | Languages |
| ALGOL 58, ALGOL 60, ALGOL 68, AWK, Julia, Modula, Pascal, Object Pascal, C#, S-Lang Icon, Unicon |
or etc. or or etc. | APL |
| ActionScript, C, CFML, Ch, Cobra, C++, D, Go, Haxe, Java, JavaScript, Lingo, Lua, Nim, Objective-C, Perl, PHP, Python, R, Ruby, Rust, Swift |
| Perl, Windows PowerShell, XPath/XQuery |
| Raku |
| or etc. | Ada, ALGOL W, BASIC, COBOL, Fortran, RPG, GNU Octave, MATLAB, PL/I, Scala, Visual Basic, Visual Basic (.NET), Xojo |
| XPath/XQuery |
| OCaml |
| F#, OCaml |
| Red |
| Haskell |
| XPath/XQuery |
| Scheme |
| Common Lisp |
| ISLISP |
| Mathematica, Wolfram Language |
| Smalltalk |
| Objective-C |
SlicingThe following list contains syntax examples of how a range of element of an array can be accessed. In the following table:
- – the index of the first element in the slice
- – the index of the last element in the slice
- – one more than the index of last element in the slice
- – the length of the slice
- – the number of array elements in each
| Format | Languages | | ALGOL 68, Julia, Icon, Unicon | | APL | | Python | | Go | | Pascal, Object Pascal, Delphi, Nim | | Windows PowerShell | | Perl | | Ruby | | Red | | Ada | | Fortran, GNU Octave, MATLAB | | Mathematica, Wolfram Language | | S-Lang | | F# | | Haxe, JavaScript, Scala | | CFML | | PHP | | Common Lisp | | ISLISP | | OCaml | | Objective-C |
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 | | 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 | | D | 0 | yes | no | varies | yes | yes | ? | | F# | 0 | no | partial | checked | yes | heap | yes | | 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 | | 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 | 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 | | 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 | | Scheme | 0 | ? | no | checked | array of array | init | yes | | 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 | | 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 |
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, and to produce a third, it is only necessary to write c = a + b In addition to support for vectorized arithmetic and relational operations, these languages also vectorize common mathematical functions such as sine. For example, if is an array, then y = sin will result in an array whose elements are sine of the corresponding elements of the array. Vectorized index operations are also supported. As an example,
even = x; odd = x;
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 y = sin; y = 0.5;
|
|