Content deleted Content added
m a) Move Julia, and change to "yes, also array of array", "yes" alone seems not correct (is it ever? or does the rest have some meaning I missed?). b) Changed color for AWK, was likely wrong, otherwise unclear what it meant. |
SilkPyjamas (talk | contribs) m Adding local short description: "List of programming language comparisons", overriding Wikidata description "Wikimedia list article" |
||
(28 intermediate revisions by 18 users not shown) | |||
Line 1:
{{Short description|List of programming language comparisons}}
{{one source|date=June 2013}}
{{ProgLangCompare}}
Line 7 ⟶ 8:
=== Array dimensions ===
The following list contains [[programming language syntax|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.
{| class="wikitable sortable"
Line 23:
|-
| [[ALGOL 68]]
| {{Mono|UPB ''name'' - LWB ''name''+1}}
{{Mono|2 UPB ''name''}}
|-
| [[APL (programming language)|APL]]
| {{Mono|⍴ ''name''
|-
| [[AWK]]
| {{Mono|''length''}} || {{Mono|1}} || {{Mono|''asorti''}}
|-
| [[C Sharp (programming language)|C#]], [[Visual Basic (.NET)]], [[Windows PowerShell]], [[F Sharp (programming language)|F#]]
| {{Mono|''name''.Length}} || {{Mono|''name''.GetLowerBound(''dimension'')}} || {{Mono|''name''.GetUpperBound(''dimension'')}}
|-
| [[CFML]]
| {{Mono|arrayLen(''name'')}}
|-
| [[Ch (computer programming)|Ch]]
Line 48:
|-
| [[Fortran]]
| {{Mono|
|-
| [[Go (programming language)|Go]]
| {{Mono|len(''name'')}} || {{Mono|0}} || {{Mono|len(''name'') - 1}}
|-
| [[
| {{Mono|rangeSize (bounds ''name'')}} || {{Mono|fst (bounds ''name'')}} || {{Mono|snd (bounds ''name'')}}
|-
Line 67:
| [[J (programming language)|J]]
| {{Mono|#''name''}} || {{Mono|0}} || {{Mono|<:@#''name''}}
|[[JavaScript]] ([[ECMAScript version history#13th Edition – ECMAScript 2022|ES2022]])
| {{Mono|''name''.length}} || {{Mono|0}}<br/>{{Mono|''name''.at(0)<ref name="es2022-array">
{{Cite web|url=https://tc39.es/ecma262/multipage/indexed-collections.html#sec-array.prototype.at|title=ECMAScript® 2025 Language Specification}}
</ref>}} || {{Mono|''name''.length - 1}}<br/>{{Mono|''name''.at(-1)<ref name="es2022-array"/>}}
|-
| [[Julia (programming language)|Julia]]
Line 75 ⟶ 80:
|-
| [[LiveCode]]
| {{Mono|length(''name'')}} || {{Mono|1}}
|-
| [[Lua (programming language)|Lua]]
Line 81 ⟶ 86:
|-
| [[Mathematica]]
| {{Mono|Length[''name'']}} || {{Mono|1}}
|-
| [[MATLAB]], [[GNU Octave]]
Line 106 ⟶ 111:
| [[PHP]]
| {{Mono|count(''name'')}} || {{Mono|0}} || {{Mono|count(''name'') - 1}}
|-▼
| [[PL/I]]
| {{Mono|dim(''name''[,dim])}} || {{Mono|lbound(''name''[,dim])}} || {{Mono|hbound(''name''[,dim])}}
|-
| [[Python (programming language)|Python]]
| {{Mono|len(''name'')}} || {{Mono|0}} || {{Mono|-1}}
|-
| [[R (programming language)|R]]
Line 117 ⟶ 125:
|-
| [[Red (programming language)|Red]]
| {{Mono|length? ''name''}} || {{Mono|''name''/1}}
|-
| [[Ruby (programming language)|Ruby]]
| {{Mono|''name''.size}} || {{Mono|0}}
|-
| [[Rust (programming language)|Rust]]
| {{Mono|''name''.len()}} || {{Mono|0}} || {{Mono|''name''.len() - 1}}
|-
| [[
| {{Mono|length(''name'')}} || {{Mono|0}} || {{Mono|-1}}
|-
| [[Scheme (programming language)|Scheme]]
Line 132 ⟶ 140:
|-
| [[Smalltalk]]
| {{Mono|''name'' size}} || {{Mono|1}}
|-
| [[Swift (programming language)|Swift]]
Line 146 ⟶ 154:
|-
| [[Wolfram Language]]
| {{Mono|Length[''name'']}} || {{Mono|1}}
|-
| [[Xojo]]
Line 152 ⟶ 160:
|-
| [[XPath]]/[[XQuery]]
| {{Mono|count($''name'')}} || {{Mono|1}} || {{Mono|count($''name'')}}
|}
Line 165 ⟶ 173:
! scope="col" | Languages
|-
| {{nowrap|{{Mono|name'''['''index''']'''}} or {{mono|name'''['''index<sub>1</sub>''',''' index<sub>2</sub>''']'''}} etc.}}
| [[ALGOL 58]], [[ALGOL 60]], [[ALGOL 68]], [[AWK]], [[Julia (programming language)|Julia]], [[Modula]], [[Pascal (programming language)|Pascal]], [[Object Pascal]], [[C Sharp (programming language)|C#]], [[
|-
| {{Mono|name'''['''index''']'''}} or {{mono|name'''['''index<sub>1</sub>''';''' index<sub>2</sub>''']'''}} etc.<br>or {{mono|index'''⌷'''name}} or {{mono|index<sub>1</sub> index<sub>2</sub>'''⌷'''name}} etc.
| [[APL (programming language)|APL]]
|-
Line 180 ⟶ 188:
| [[Raku (programming language)|Raku]]
|-
| {{Mono|name'''('''index''')'''}} or {{mono|name'''('''index<sub>1</sub>''',''' index<sub>2</sub>''')'''}} etc.
| [[Ada (programming language)|Ada]], [[ALGOL W]], [[BASIC]], [[COBOL]], [[Fortran]], [[IBM RPG|RPG]], [[GNU Octave]], [[MATLAB]], [[PL/I]], [[Scala (programming language)|Scala]], [[Visual Basic]], [[Visual Basic (.NET)]], [[Xojo]]
|-
| {{Mono|'''$'''name'''('''index''')'''}}
Line 196 ⟶ 204:
|-
| {{Mono|name''' ! '''index}}
| [[
|-
| {{Mono|'''$'''name''' ? '''index
| [[XPath]]/[[XQuery]]<ref name="xpath"/>
|-
Line 222 ⟶ 230:
| [[J (programming language)|J]]
|-
| {{Mono|name.item(index)}} or {{mono|name @ index<ref>{{Cite web|url=http://smarteiffel.loria.fr/libraries/api/lib.d/storage.d/loadpath.se.d/collection.d/ARRAY/ANY.html|title=Eiffeldoc : ARRAY}}</ref>}}
| [[Eiffel (programming language)|Eiffel]]
|}
Line 243 ⟶ 251:
|-
| {{Mono|name'''['''first''':'''last''']'''}}
| [[ALGOL 68]],<ref name="s1"/> [[Julia (programming language)|Julia]], [[Icon (programming language)|Icon]], [[Unicon (programming language)|Unicon]]
|-
| {{Mono|name'''['''first'''+(⍳'''len''')-⎕IO]'''}}
Line 255 ⟶ 263:
|-
| {{Mono|name'''['''first'''..'''last''']'''}}
| [[Pascal (programming language)|Pascal]], [[Object Pascal]], [[Delphi (
|-
| {{Mono|'''$'''name'''['''first'''..'''last''']'''}}
Line 263 ⟶ 271:
| [[Perl]]<ref name="s3"/>
|-
| {{Mono|name'''['''first'''..'''last''']'''
| [[Ruby (programming language)|Ruby]]<ref name="s4"/>
|-
Line 279 ⟶ 287:
|-
| {{Mono|name'''{{brackets|'''first''':'''last'''}}'''}}
| [[
|-
| {{Mono|name'''.['''first'''..'''step'''..'''last''']'''}}
Line 308 ⟶ 316:
| [[J (programming language)|J]]
|-
| {{Mono|name'''['''first'''..<'''end''']'''
| [[Swift (programming language)|Swift]]
|-
| {{Mono|name '''copyFrom:''' first '''to:'''last
| [[Smalltalk]]
|-
| {{Mono|name'''['''first'''..'''end''']'''
| [[D (programming language)|D]], [[C sharp (programming language)|C#]]<ref name="s5" /><ref name="s6" />
|-
| {{Mono|name'''['''first'''..'''end''']'''
| [[Rust (programming language)|Rust]]
|-
| {{Mono|name'''['''first''':'''end''']'''
| [[Cobra (programming language)|Cobra]]
|-
Line 520 ⟶ 528:
| style="background:honeydew;" | yes
|-
| [[
| style="background:cornsilk;" | 0
| style="background:honeydew;" | yes<ref name="cr24"/>
Line 702 ⟶ 710:
| [[PL/I]]
| style="background:azure;" | 1
| style="background:grey80;" |
| style="background:honeydew;" | yes
| style="background:honeydew;" |
| style="background:honeydew;" | yes
| style="background:seashell;" | no
| style="background:grey80;" |
|-
| [[Python (programming language)|Python]]
Line 759 ⟶ 767:
| style="background:seashell;" | no
| style="background:honeydew;" | checked
| style="background:
| style="background:grey80;" |
| style="background:grey80;" | ?
|-
Line 772 ⟶ 780:
| style="background:grey80;" | ?
|-
| [[
| style="background:cornsilk;" | 0
| style="background:grey80;" | ?
Line 817 ⟶ 825:
| style="background:grey80;" | ?
|-
| [[Visual Basic (classic)]]
| style="background:
| style="background:seashell;" | no
| style="background:honeydew;" | yes
Line 826 ⟶ 834:
| style="background:grey80;" | ?
|-
| [[Visual Basic (.NET)]]
| style="background:
| style="background:seashell;" | no
| style="background:cornsilk;" | partial<ref name="dotnetarray"/>
Line 873 ⟶ 881:
== Vectorized array operations ==
Some compiled languages such as [[Ada (programming language)|Ada]] and [[Fortran]], and some scripting languages such as [[IDL (programming language)|IDL]], [[MATLAB]], and [[
▲Some compiled languages such as [[Ada (programming language)|Ada]] and [[Fortran]], and some scripting languages such as [[IDL (programming language)|IDL]], [[MATLAB]], and [[S-Lang (programming library)|S-Lang]], have native support for vectorized operations on arrays. For example, to perform an element by element sum of two arrays, {{Mono|a}} and {{Mono|b}} to produce a third {{Mono|c}}, 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 {{Mono|x}} is an array, then
will result in an array {{Mono|y}} whose elements are sine of the corresponding elements of the array {{Mono|x}}.
Vectorized index operations are also supported.
<syntaxhighlight lang="fortran">
</syntaxhighlight>
is how one would use [[Fortran]] to create arrays from the even and odd entries of an array.
=== Mathematical matrix operations ===
{| class="wikitable"
! scope="col" | Language/<br>Library
! scope="col" | Create
Line 907 ⟶ 914:
| {{code|2=apl|⍉m}}
| {{code|2=apl|m[i;j]}} or {{code|2=apl|i j⌷m}}
| {{code|2=apl|m[;j]}} or {{code|2=apl|j⌷[2]m}} or
| {{code|2=apl|m[i;]}} or {{code|2=apl|i⌷m}}
| {{code|2=apl|⌹⍠1⊢m}}
Line 928 ⟶ 935:
| {{code|shape(m,1)}}
| {{code|eigen(output, m, NULL)}}
|-▼
| [[Julia_(programming_language)|Julia]] and its standard library<br/> {{code|LinearAlgebra}}
| {{code|lang=julia|code=m = [1 2; 3 4]}} or
<syntaxhighlight lang="julia">
m = [
1 2
3 4
]
</syntaxhighlight>
| {{code|lang=julia|det(m)}}
| {{code|lang=julia|transpose(m)}} or<br/>
{{code|lang=julia|m'}} for real matrices
| {{code|lang=julia|m[i, j]}}
| {{code|lang=julia|m[:, j]}}
| {{code|lang=julia|m[i, :]}}
| {{code|lang=julia|eigen(m).values}}
|-
| [[Mathematica]] /<br/>[[Wolfram Language]]
Line 955 ⟶ 978:
| {{code|m[i-1,:]}}
| {{code|linalg.eigvals(m)}}
|-▼
| [[R_(programming_language)|R]]
| {{code|1=m <- matrix(...)}} or {{code|1=m <- array(...)}}
| {{code|det(m)}}
| {{code|t(m)}}
| {{code|m[i, j]}}
| {{code|m[, j]}}
| {{code|m[i, ]}}
| {{code|eigen(m)}}
|-
| [[S-Lang]]
Line 967 ⟶ 999:
| [[SymPy]]
| {{code|1=m = Matrix(...)}}
| {{code|m.det()}}
▲|
| {{code|m.T}}
| {{code|m[i-1,j-1]}}
| {{code|m.col(j-1)}}
▲|
| {{code|m.row(i-1)}}
▲|
| {{code|m.eigenvals()}}
▲|
|-
|}
Line 983 ⟶ 1,015:
<ref name="s1">Slices for multidimensional arrays are also supported and defined similarly.</ref>
<ref name="s2">Slices of the type <code>''first'':''last'':''step''</code> are also supported.</ref>
<ref name="s3">More generally, for 1-d arrays [[Perl]] and [[
<ref name="s4">{{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.</ref>
<ref name="s5">[[C Sharp (programming language)|C#]] 8.0 proposed feature ({{as of|2019|08|29|lc=y}})</ref>
<ref name="s6">{{cite web |title=Ranges - C# 8.0 language proposals |url=https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-8.0/ranges |website=Microsoft Docs |publisher=Microsoft |accessdate=29 August 2019}}</ref>
Line 992 ⟶ 1,024:
<ref name="cr3">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.</ref>
<ref name="cr4">C99 allows for variable size arrays; however there is almost no compiler available to support this new feature</ref>
<ref name="cr5">This list is strictly comparing language features. In every language (even
<ref name="cr6">The class Array is fixed-size, but OrderedCollection is dynamic</ref>
<ref name="cr7">The indexing base can be 0 or 1 as per the System Variable {{Mono|⎕IO}}.
<ref name="cr8">At least 2 dimensions (scalar numbers are 1×1 arrays, vectors are 1×n or n×1 arrays).</ref>
<ref name="cr9">Allows creating fixed-size arrays in "unsafe" code, allowing enhanced [[interoperability]] with other language</ref>
<ref name="cr10">Varies by implementation. Newer implementations (
<ref name="cr11">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</ref>
<ref name="cr12">Almost all Fortran implementations offer bounds checking options via compiler switches.
<ref name="cr13">Many implementations ([[Turbo Pascal]], [[Object Pascal]] ([[Delphi (software)|Delphi]]),
<ref name="cr14">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</ref>
<ref name="cr15">Most Common Lisp implementations allow checking to be selectively disabled</ref>
<ref name="cr16">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]]</ref>
<ref name="cr17">The default base index is the lowest value of the index type used</ref>
<ref name="cr18">Standard [[Perl]] array data types do not support vectorized operations as defined here.
<ref name="cr19">The standard [[Python (programming language)|Python]] array type, <code>list</code>, does not support vectorized operations as defined here.
<ref name="cr20">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.</ref>
<ref name="cr21">FreeBASIC supports both variable array lengths and fixed length arrays.
<ref name="cr22">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
<ref name="cr23">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"</ref>
<ref name="cr24">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</ref>
<ref name="cr25">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}}.
<ref name="cr26">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.</ref>
<ref name="cr27">COBOL arrays may be indexed with "INDEX" types, distinct from integer types</ref>
<ref name="cr28">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</ref>
<ref name="cr29">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.</ref>
<ref name="cr30">Size can be chosen when the array is declared, or when it is allocated, after which it is fixed.</ref>
<ref name="dotnetarray">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.</ref>
<ref name="xpath">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
<ref name="msbasicarrays">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).</ref>
}}
|