From Surf Wiki (app.surf) — the open knowledge base
Comparison of programming languages (array)
List of programming language comparisons
List of programming language comparisons
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 | ||||
| ALGOL 68 | ||||
| etc. | ||||
| etc. | ||||
| APL | ||||
| AWK | ||||
| C#, Visual Basic (.NET), Windows PowerShell, F# | ||||
| CFML | ||||
| Ch | ||||
| Common Lisp | ||||
| D | ||||
| Fortran | ||||
| Go | ||||
| Haskell | ||||
| ISLISP | ||||
| Icon | ||||
| Cobra, D, Haxe, Java, JavaScript, Scala | ||||
| J | {{Mono | |||
| JavaScript (ES2022) | ||||
| {{Mono | name.at(0) | |||
| Julia | ||||
| Lingo | ||||
| LiveCode | ||||
| Lua | ||||
| Mathematica | ||||
| MATLAB, GNU Octave | ||||
| Nim | ||||
| Oberon | ||||
| Object Pascal | ||||
| Objective-C (`NSArray *` only) | ||||
| OCaml | ||||
| Perl | ||||
| PHP | ||||
| PL/I | ||||
| Python | ||||
| R | ||||
| Raku | @ | |||
| Red | ||||
| Ruby | ||||
| Rust | ||||
| S-Lang | ||||
| Scheme | ||||
| Smalltalk | ||||
| Swift | ||||
| Unicon | ||||
| Visual Basic | ||||
| Wolfram Language | ||||
| Xojo | ||||
| XPath/XQuery | ||||
Indexing
The following list contains syntax examples of how to access a single element of an array.
| Format | Languages |
|---|---|
| or etc. | 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 (`NSArray *`), 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 (`NSArray *` only) | |
| J | |
| or | Eiffel |
Slicing
The 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 (= end - first)
- – the number of array elements in each (default 1)
| Format | Languages | |
|---|---|---|
| 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 (`NSArray *` only) | ||
| J | ||
| {{Mono | name**first.. | [Swift |
| Smalltalk | ||
| D, C# | ||
| Rust | ||
| 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 |
| 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, 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 (x)
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(2::2);
odd = x(::2);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(x); y[where(abs(y)0.5)] = 0.5;
Mathematical matrix operations
| Language/ | ||||||||
|---|---|---|---|---|---|---|---|---|
| Library | Create | Determinant | Transpose | Element | Column | Row | Eigenvalues | |
| APL | or | or or | ||||||
| or | or | |||||||
| Fortran | ||||||||
| Ch | } | |||||||
| Julia and its standard library | ||||||||
| or | or | |||||||
| Mathematica / | ||||||||
| Wolfram Language | {{x11, x12, ...}, ...} | |||||||
| MATLAB / | ||||||||
| GNU Octave | ||||||||
| NumPy | ||||||||
| R | {{code | 1=m | ||||||
| S-Lang | ||||||||
| SymPy |
References
References
- "Programming in Lua : 11.1".
- "Nim Tutorial (Part I)".
- "Eiffeldoc : ARRAY".
- "Lua 5.3 Reference Manual".
- [http://dlang.org/hash-map.html Associative Arrays - D Programming Language]
- "Nim Compiler User Guide".
- "Vectorization - R-style logical vector operation in Nim".
- [http://www.softintegration.com/products/features/ch_vs_matlab.html Ch numerical features]
- The index may be a negative number, indicating the corresponding number of places before the end of the array.
- Slices for multidimensional arrays are also supported and defined similarly.
- Slices of the type
''first'':''last'':''step''are also supported. - More generally, for 1-d arrays [[Perl]] and [[S-Lang]] allow slices of the form
''array''[''indices''], where''indices''can be a range such mentioned in footnote 2 or an explicit list of indices, e.g., '[0,9,3,4]', or a mix of both, e.g.,A[[[0:3]],7,9,[11:2:-3]]]. - {{Mono. ''last'' or {{Mono. ''end'' may be a negative number, indicating to stop at the corresponding number of places before the end of the array.
- [[C Sharp (programming language). C#]] 8.0 proposed feature ({{as of. 2019. 08. 29
- "Ranges - C# 8.0 language proposals". Microsoft.
- Size can only be chosen on initialization after which it is fixed.
- Allows arrays of arrays which can be used to emulate most—but not all—aspects multi-dimensional arrays
- Size can only be chosen on initialization when memory is allocated on the heap, as distinguished from when it is allocated on the stack. This note need not be made for a language that always allocates arrays on the heap.
- C99 allows for variable size arrays; however there is almost no compiler available to support this new feature
- This list is strictly comparing language features. In every language (even [[assembly language]]) it is possible to provide improved array handling via add on libraries. This language has improved array handling as part of its standard library
- The class Array is fixed-size, but OrderedCollection is dynamic
- The indexing base can be 0 or 1 as per the System Variable {{Mono. ⎕IO. This value may apply to the whole "workspace", or be localized to a user-defined function or a single primitive function by use of the Variant operator ({{Mono. ⍠).
- At least 2 dimensions (scalar numbers are 1×1 arrays, vectors are 1×n or n×1 arrays).
- Allows creating fixed-size arrays in "unsafe" code, allowing enhanced [[interoperability]] with other language
- Varies by implementation. Newer implementations ([[Free Pascal]], [[Object Pascal]] ([[Delphi (software). Delphi]])) allow heap-based dynamic arrays.
- Behaviour can be tuned via compiler switches. As in DMD 1.0 bounds are checked in debug mode and unchecked in release mode for efficiency
- Almost all Fortran implementations offer bounds checking options via compiler switches. However by default, bounds checking is usually turned off for efficiency
- Many implementations ([[Turbo Pascal]], [[Object Pascal]] ([[Delphi (software). Delphi]]), [[Free Pascal]]) allow the behaviour to be changed by compiler switches and in-line directives
- COBOL provides a way to specify that the usable size of an array is variable, but this can never be greater than the declared maximum size, which is also the allocated size
- Most Common Lisp implementations allow checking to be selectively disabled
- The index type can be a freely chosen [[integer (computer science). integer type]], [[enumerated type]], or [[character (computing). character type]]. For arrays with non-compact index types see: [[Associative array]]
- The default base index is the lowest value of the index type used
- Standard [[Perl]] array data types do not support vectorized operations as defined here. However, the [[Perl Data Language]] extension adds array objects with this ability.
- The standard [[Python (programming language). Python]] array type,
list, does not support vectorized operations as defined here. However, the [[numpy]] extension adds array objects with this ability - By specifying a base index, arrays at an arbitrary base can be created. However, by default, Lua's length operator does not consider the base index of the array when calculating the length. This behavior can be changed via metamethods.
- FreeBASIC supports both variable array lengths and fixed length arrays. Arrays declared with no index range are created as variable-length arrays, while arrays with a declared range are created as fixed-length arrays
- In these languages, one can access or write to an array index greater than or equal to the length of the array, and the array will implicitly grow to that size. This may appear at first as if the bounds are not checked; however, the bounds are checked to decide to grow the array, and you do not have unsafe memory access like you do in C.
- PHP's "arrays" are associative arrays. You can use integers and strings as the keys (indexes); floats can also be used as the key but are truncated to integers. There is not really any "base index" or "bounds"
- Haskell arrays (Data.Array) allow using any type which is an instance of Ix as index type. So a custom type can be defined and used as an index type as long as it instances Ix. Also, tuples of Ix types are also Ix types; this is commonly used to implement multi-dimensional arrays
- ALGOL 68 arrays must be subscripted (and sliced) by type {{Mono. INT. However a hash function could be used to convert other types to {{Mono. INT. e.g. {{Mono. name'''['''hash("string")''']'''
- Because C does not bound-check indices, a pointer to the interior of any array can be defined that will symbolically act as a pseudo-array that accommodates negative indices or any integer index origin.
- COBOL arrays may be indexed with "INDEX" types, distinct from integer types
- While COBOL only has arrays-of-arrays, array elements can be accessed with a multi-dimensional-array-like syntax, where the language automatically matches the indexes to the arrays enclosing the item being referenced
- While Golang's Array type is not dynamically sized, the data type [https://tour.golang.org/moretypes/7 Slice] is dynamically-sized and is much more common in use than arrays.
- Size can be chosen when the array is declared, or when it is allocated, after which it is fixed.
- The base can be changed when initializing with {{Mono. System.Array.CreateInstance (which returns {{Mono. System.Array), but not when using the language syntax. Arrays with non-zero base indices are not the same type as those with zero base indices and cannot be manipulated using language syntax (the {{Mono. GetValue and {{Mono. SetValue methods must be used instead) or downcast to a specific type ({{Mono. T[] in [[C Sharp (programming language). C#]], or {{Mono. T() in VB.NET), preventing breakage of code assuming base indices of zero.
- XPath/XQuery has two kinds of arrays. ''Sequences'' {{Mono. (1,2,3) which cannot nest and in the XPath/XQuery 3.1 version ''arrays'' {{Mono. array { 1,2,3} or {{Mono. [1,2,3] which can.
- Microsoft QBASIC, [[QuickBASIC]], Visual Basic, and VBA all had/have the ability to specify ''Option Base 1'', which caused all arrays in the module to default starting at 1 instead of 0. Support for ''Option Base'' was phased out in [[Visual Basic (.NET)]]. In various Microsoft BASIC implementations, arrays can be DIMensioned using ''to'' to specify the minimum and maximum index values (e.g. {{Mono. DIM MyArray(2 to 50) AS STRING would have the first index at 2 instead of the default).
This article was imported from Wikipedia and is available under the Creative Commons Attribution-ShareAlike 4.0 License. Content has been adapted to SurfDoc format. Original contributors can be found on the article history page.
Ask Mako anything about Comparison of programming languages (array) — get instant answers, deeper analysis, and related topics.
Research with MakoFree with your Surf account
Create a free account to save articles, ask Mako questions, and organize your research.
Sign up freeThis content may have been generated or modified by AI. CloudSurf Software LLC is not responsible for the accuracy, completeness, or reliability of AI-generated content. Always verify important information from primary sources.
Report