Comparison of programming languages (array): Difference between revisions

Content deleted Content added
Default base index for BASIC arrays is 0 - DIM a(10) declares an array of 11 elements with indices from 0 to 10.
m Adding local short description: "List of programming language comparisons", overriding Wikidata description "Wikimedia list article"
 
(338 intermediate revisions by more than 100 users not shown)
Line 1:
{{Short description|List of programming language comparisons}}
{{one source|date=June 2013}}
{{ProgLangCompare}}
 
This '''comparison of programming languages (array)''' compares the features of [[array data structure]]s or [[matrix (mathematics)|matrix]] processing for various computer [[programming language]]s.
 
== Syntax ==
 
=== 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.
The following list contains Syntax examples on how to determine the dimensions (index of the first element, the last element and or the size in elements):
 
{| class="wikitable sortable"
|-
|- align="left"
! Sizescope="col" !! First !! Last !!| Languages
! scope="col" | Size
! scope="col" | First
! scope="col" | Last
|-
| name'''<nowiki>'</nowiki>Length'''|| name'''<nowiki>'</nowiki>First''' || name'''<nowiki>'</nowiki>Last'''
| [[Ada (programming language)|Ada]]
| {{Mono|''name''<nowiki>'</nowiki>Length}} || {{Mono|''name''<nowiki>'</nowiki>First}} || {{Mono|''name''<nowiki>'</nowiki>Last}}
|-
| [[ALGOL 68]]
| '''UPB''' name - '''LWB''' name'''+1''' or <br> '''2 UPB''' name - '''2 LWB''' name'''+1''' etc|| '''LWB''' name or '''2 LWB''' name etc|| '''UPB''' name or '''2 UPB''' name etc
| {{Mono|UPB ''name'' - LWB ''name''+1}}<br/>{{Mono|2 UPB ''name'' - 2 LWB ''name''+1}}<br/>etc.|| {{Mono|LWB ''name''}}<br/>{{Mono|2 LWB ''name''}}<br/>etc.|| {{Mono|UPB ''name''}}<br/>
|[[ALGOL 68]]
{{Mono|2 UPB ''name''}}<br/>etc.
|-
| [[APL (programming language)|APL]]
| '''UBound('''name''')-LBound('''name''')+1''' || '''LBound('''name''')''' || '''UBound('''name''')'''
| {{Mono|⍴ ''name''<br/>(⍴ ''name'')[''index'']}} || {{Mono|⎕IO}} || {{Mono|(⍴ ''name'')-~⎕IO<br/>(⍴ ''name'')[''index'']-~⎕IO}}
|[[Visual Basic]]
|-
| [[AWK]]
| name'''.Length''' || name'''.GetLowerBound('''dimension''')''' || name'''.GetUpperBound('''dimension''')'''
| {{Mono|''length''}} || {{Mono|1}} || {{Mono|''asorti''}}
| [[C Sharp (programming language)|C#]], [[Visual Basic .NET]], [[Windows PowerShell]], [[F Sharp (programming language)|F#]]
|-
| [[C Sharp (programming language)|C#]], [[Visual Basic (.NET)]], [[Windows PowerShell]], [[F Sharp (programming language)|F#]]
| name'''.length''' || '''0''' || name'''.length - 1'''
| {{Mono|''name''.Length}} || {{Mono|''name''.GetLowerBound(''dimension'')}} || {{Mono|''name''.GetUpperBound(''dimension'')}}
| [[Java (programming language)|Java]], [[JavaScript]], [[D (programming language)|D]]
|-
| [[CFML]]
| {{Mono|arrayLen(''name'')}}<br/>{{Mono|''name''.len()}} || {{Mono|1}} || {{Mono|''name''.len()}}
|-
| [[Ch (computer programming)|Ch]]
| {{Mono|max(shape(''name''))}} || {{Mono|0}} || {{Mono|max(shape(''name''))-1}}
|-
| [[Common Lisp]]
| {{Mono|(length ''name'')}} || {{Mono|0}} || {{Mono|(1- (length ''name''))}}
|-
| [[D (programming language)|D]]
| {{Mono|''name''.length}} || {{Mono|0}} || {{Mono|''name''.length-1}} <br> {{Mono|$-1}}
|-
| [[Fortran]]
| {{Mono|size(''name'')}} || {{Mono|lbound(''name'')}} || {{Mono|ubound(''name'')}}
|-
| [[Go (programming language)|Go]]
| {{Mono|len(''name'')}} || {{Mono|0}} || {{Mono|len(''name'') - 1}}
|-
| [[Haskell]]
| {{Mono|rangeSize (bounds ''name'')}} || {{Mono|fst (bounds ''name'')}} || {{Mono|snd (bounds ''name'')}}
|-
| [[ISLISP]]
| {{Mono|(length ''name'')}}|| {{Mono|0}} || {{Mono|(1- (length ''name''))}}
|-
| [[Icon (programming language)|Icon]]
| {{Mono|*''name''}} || {{Mono|1}} || {{Mono|*''name''}}
|-
| [[Cobra (programming language)|Cobra]], [[D (programming language)|D]], [[Haxe]], [[Java (programming language)|Java]], [[JavaScript]], [[Scala (programming language)|Scala]]
| {{Mono|''name''.length}} || {{Mono|0}} || {{Mono|''name''.length - 1}}
|-
| [[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]]
| {{Mono|length(''name'')<br/>size(''name'')}} || {{Mono|begin<br/>first.(axes(''name''))}} || {{Mono|end<br/>last.(axes(''name''))}}
|-
| [[Lingo (programming language)|Lingo]]
| {{Mono|count(''name'')}} || {{Mono|1}} || {{Mono|getLast(''name'')}}
|-
| [[LiveCode]]
| {{Mono|length(''name'')}} || {{Mono|1}}<br/>{{Mono|first}} || {{Mono|-1}}<br/>{{Mono|last}}
|-
| [[Lua (programming language)|Lua]]
| {{Mono|#''name''}} || {{Mono|1 by convention; any integer<ref>{{Cite web|url=https://www.lua.org/pil/11.1.html|title=Programming in Lua : 11.1}}</ref>}} || {{Mono|#''name''}}
|-
| [[Mathematica]]
| {{Mono|Length[''name'']}} || {{Mono|1}}<br/>{{Mono|First[''name'']}} || {{Mono|-1}}<br/>{{Mono|Last[''name'']}}
|-
| [[MATLAB]], [[GNU Octave]]
| {{Mono|length(''name'')}} || {{Mono|1}} || {{Mono|end}}
|-:
| [[Nim (programming language)|Nim]]
| {{Mono|''name''.len}} || {{Mono|''name''.low}}<ref name="nim-lang.org">{{Cite web|url=https://nim-lang.org/docs/tut1.html#advanced-types-arrays|title=Nim Tutorial (Part I)}}</ref> || {{Mono|''name''.high}}
|-
| [[Oberon (programming language)|Oberon]]
| {{Mono|LEN(''name'')}} || {{Mono|0}} || {{Mono|LEN(''name'') - 1}}
|-
| [[Object Pascal]]
| {{Mono|Length(''name'')}} || {{Mono|0}}<br/>{{Mono|low(''name'')}} || {{Mono|Length(''name'')-1}}<br/>{{Mono|high(''name'')}}
|-
| [[Objective-C]] (<code>NSArray *</code> only)
| {{Mono|[''name'' count]}} || {{Mono|0}} || {{Mono|[''name'' count] - 1}}
|-
| [[OCaml]]
| {{Mono|Array.length ''name''}}|| {{Mono|0}} || {{Mono|Array.length ''name'' - 1}}
|-
| '''scalar(@'''name''')''' || '''$[''' || '''$#'''name
| [[Perl]]
| {{Mono|scalar(@''name'')}} || {{Mono|$[}} || {{Mono|$#''name''}}
|-
| [[PHP]]
| @name'''.elems''' || '''0''' || @name'''.end'''
| {{Mono|count(''name'')}} || {{Mono|0}} || {{Mono|count(''name'') - 1}}
| [[Perl 6]]
|-
| [[PL/I]]
| name'''.size''' || '''0''' (name'''.first''' will also refer to this element) || '''-1''' or name'''.size - 1''' (name'''.last''' will also refer to this element)
| {{Mono|dim(''name''[,dim])}} || {{Mono|lbound(''name''[,dim])}} || {{Mono|hbound(''name''[,dim])}}
| [[Ruby (programming language)|Ruby]]
|-
| '''len('''name''')''' || '''0''' || '''-1''' or '''len('''name''') - 1'''
| [[Python (programming language)|Python]]
| {{Mono|len(''name'')}} || {{Mono|0}} || {{Mono|-1}}<br/>{{Mono|len(''name'') - 1}}
|-
| [[R (programming language)|R]]
| '''length('''name''')''' || '''0''' || '''-1''' or '''length('''name''')-1'''
| {{Mono|length(''name'')}} || {{Mono|1}} || {{Mono|length(''name'')}}
| [[S-Lang_(programming_language)|S-Lang]]
|-
| [[Raku (programming language)|Raku]]
| @{{Mono|''name''.elems}} || {{Mono|0}} || {{Mono|@''name''.end}}
|-
| [[Red (programming language)|Red]]
| {{Mono|length? ''name''}} || {{Mono|''name''/1}}<br/>{{Mono|first ''name''}} || {{Mono|last ''name''}}
|-
| [[Ruby (programming language)|Ruby]]
| {{Mono|''name''.size}} || {{Mono|0}}<br/>{{Mono|''name''.first}} || {{Mono|-1}}<br/>{{Mono|''name''.size - 1}}<br/>{{Mono|''name''.last}}
|-
| [[Rust (programming language)|Rust]]
| {{Mono|''name''.len()}} || {{Mono|0}} || {{Mono|''name''.len() - 1}}
|-
| [[S-Lang]]
| {{Mono|length(''name'')}} || {{Mono|0}} || {{Mono|-1}}<br/>{{Mono|length(''name'')-1}}
|-
| '''(vector-length '''vector''')''' || '''0''' || '''(- (vector-length '''vector''') 1)'''
| [[Scheme (programming language)|Scheme]]
| {{Mono|(vector-length ''vector'')}} || {{Mono|0}} || {{Mono|(- (vector-length ''vector'') 1)}}
|-
| [[Smalltalk]]
| '''(length '''name''')'''|| '''0''' || '''(1- (length '''name'''))'''
| {{Mono|''name'' size}} || {{Mono|1}}<br/>{{Mono|''name'' first}} || {{Mono|''name'' size}}<br/>{{Mono|''name'' last}}
| [[Common Lisp programming language|Common Lisp]]
|-
| [[Swift (programming language)|Swift]]
| '''Array.length '''name|| '''0''' || '''Array.length '''name''' - 1'''
| {{Mono|''name.''count}}
| [[OCaml]]
| {{Mono|0}}
| {{Mono|''name.''count - 1}}
|-
| [[Unicon (programming language)|Unicon]]
| '''rangeSize (bounds '''name''')''' || '''fst (bounds '''name''')''' || '''snd (bounds '''name''')'''
| {{Mono|*''name''}} || {{Mono|1}} || {{Mono|*''name''}}
| [[Haskell (programming language)|Haskell]]
|-
| [[Visual Basic]]
| '''['''name''' count]''' || '''0''' || '''['''name''' count] - 1'''
| {{Mono|UBound(''name'')-LBound(''name'')+1}} || {{Mono|LBound(''name'')}} || {{Mono|UBound(''name'')}}
| [[Objective-C]] (<code>NSArray *</code> only)
|-
| [[Wolfram Language]]
| {{Mono|Length[''name'']}} || {{Mono|1}}<br/>{{Mono|First[''name'']}} || {{Mono|-1}}<br/>{{Mono|Last[''name'']}}
|-
| [[Xojo]]
| {{Mono|UBound(''name'')}} || {{Mono|0}} || {{Mono|UBound(''name'')}}
|-
| [[XPath]]/[[XQuery]]
| {{Mono|count($''name'')}} || {{Mono|1}} || {{Mono|count($''name'')}}<br/>{{Mono|last()}}<br/>{{Mono|array:size(''name'')}}<ref name="xpath"/>
 
|}
 
=== [[Array#Indexing|Indexing]] ===
 
The following list contains Syntaxsyntax examples onof how to access a single element of an array can be accessed.
 
{| class="wikitable"
|-
|- align="left"
! scope="col" | Format
! Format !! Languages
! 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#]], [[S-Lang]]<ref name="indexing"/> [[Icon (programming language)|Icon]], [[Unicon (programming language)|Unicon]]
|-
| {{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.
| name'''['''index''']'''
| [[APL (programming language)|APL]]
| [[C (programming language)|C]], [[C++]], [[D (programming language)|D]], [[Java (programming language)|Java]], [[JavaScript]], [[Perl]]<sup>1</sub>, [[PHP]], [[Python (programming language)|Python]]<sup>1</sub>, [[Ruby (programming language)|Ruby]]<sup>1</sub>, [[S-Lang_(programming_language)|S-Lang]]<sup>1</sub>
|-
| '''$'''{{Mono|name'''['''index''']'''}}
| [[ActionScript]], [[C (programming language)|C]], [[CFML]], [[Ch (computer programming)|Ch]], [[Cobra (programming language)|Cobra]], [[C++]], [[D (programming language)|D]], [[Go (programming language)|Go]], [[Haxe]], [[Java (programming language)|Java]], [[JavaScript]], [[Lingo (programming language)|Lingo]], [[Lua (programming language)|Lua]], [[Nim (programming language)|Nim]], [[Objective-C]] (<code>NSArray *</code>), [[Perl]],<ref name="indexing"/> [[PHP]], [[Python (programming language)|Python]],<ref name="indexing"/> [[R (programming language)|R]], [[Ruby (programming language)|Ruby]],<ref name="indexing"/> [[Rust (programming language)|Rust]], [[Swift (programming language)|Swift]]
| [[Perl]]<sup>1</sub>, [[PHP]], [[Windows PowerShell]]<sup>1</sub>
|-
| {{Mono|'''@$'''name'''['''index''']'''}}
| [[Perl]],<ref name="indexing"/> [[Windows PowerShell]],<ref name="indexing"/> [[XPath]]/[[XQuery]]<ref name="xpath"/>
| [[Perl 6]]
|-
| {{Mono|'''@'''name'''(['''index''')]'''}}
| [[AdaRaku (programming language)|Ada]], [[Fortran]], [[Visual Basic]], [[Visual Basic .NETRaku]]
|-
| {{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''')'''}}
| [[XPath]]/[[XQuery]]<ref name="xpath"/>
|-
| {{Mono|name'''.('''index''')'''}}
| [[OCaml]]
|-
| {{Mono|name'''.['''index''']'''}}
| [[F Sharp (programming language)|F#]], [[OCaml]]
|-
| {{Mono|name''' ! '''/index}}
| [[HaskellRed (programming language)|HaskellRed]]
|-
| '''(vector-ref{{Mono|name''' name! index''')'''index}}
| [[Haskell]]
|-
| {{Mono|'''$'''name''' ? '''index}}
| [[XPath]]/[[XQuery]]<ref name="xpath"/>
|-
| {{Mono|'''(vector-ref''' name index''')'''}}
| [[Scheme (programming language)|Scheme]]
|-
| {{Mono|'''(aref''' name index''')'''}}
| [[Common Lisp programming language|Common Lisp]]
|-
| {{Mono|'''[(elt''' name''' objectAtIndex:'''index'''])'''}}
| [[ISLISP]]
|-
| {{Mono|name'''{{brackets|'''index'''}}'''}}
| [[Mathematica]],<ref name="indexing"/> [[Wolfram Language]]
|-
| {{Mono|name''' at:'''index}}
| [[Smalltalk]]
|-
| {{Mono|'''['''name''' objectAtIndex:'''index''']'''}}
| [[Objective-C]] (<code>NSArray *</code> only)
|-
| {{Mono|index'''{'''name}}
| [[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]]
|}
# The index may be a negative number, indicating the corresponding number of places before the end of the array.
 
===[[Array slicing|Slicing]]===
 
The following list contains Syntaxsyntax examples onof how a range of element of an array can be accessed.
 
In the following table:
*''{{Mono|first''}} - the index of the first element in the slice
*''{{Mono|last''}} - the index of the last element in the slice
*''{{Mono|end''}} - one more than the index of last element in the slice
*''{{Mono|len''}} - the length of the slice (= end - first)
*{{Mono|step}} – the number of array elements in each (default 1)
 
{| class="wikitable"
|-
|- align="left"
! scope="col" | Format
! Format !! Languages
! scope="col" | Languages
|-
| {{Mono|name'''['''first''':'''last''']'''}}
| [[ALGOL 68]],<ref name="s1"/> [[Julia (programming language)|Julia]], [[Icon (programming language)|Icon]], [[Unicon (programming language)|Unicon]]
| [[ALGOL 68]]<sup>1</sup>
|-
| {{Mono|name'''['''first''':+(⍳'''endlen''')-⎕IO]'''}}
| [[PythonAPL (programming language)|PythonAPL]]<sup>2,4</sup>
|-
| {{Mono|name'''['''first'''..:'''lastend''':'''step''']'''}}
| [[DPython (programming language)|DPython]]<ref name="s2"/><ref name="s4"/>
|-
| {{Mono|name'''['''first''':'''end''']'''}}
| [[Go (programming language)|Go]]
|-
| {{Mono|name'''['''first'''..'''last''']'''}}
| [[Pascal (programming language)|Pascal]], [[Object Pascal]], [[Delphi (software)|Delphi]], [[Nim (programming language)|Nim]]
|-
| {{Mono|'''$'''name'''['''first'''..'''last''']'''}}
| [[Windows PowerShell]]
|-
| {{Mono|'''@'''name'''['''first'''..'''last''']'''}}
| [[Perl]]<sup>3<ref name="s3"/sub>
|-
| {{Mono|name'''['''first'''..'''last''']''' <br /> name'''['''first'''...'''end''']''' <br /> name'''['''first''', '''len''']'''}}
| [[Ruby (programming language)|Ruby]]<sup>4<ref name="s4"/sub>
|-
| {{Mono|copy/part skip name first len}}
| name'''('''first'''..'''last''')'''
| [[AdaRed (programming language)|AdaRed]]<sup>1</sub>
|-
| {{Mono|name'''('''first''':..'''last''')'''}}
| [[Ada (programming language)|Ada]]<ref name="s1"/>
| [[Fortran]]<sup>1,2</sub>
|-
| {{Mono|name'''[[('''first''':'''last''']])'''}}
| [[Fortran]],<ref name="s1"/><ref name="s2"/> [[GNU Octave]], [[MATLAB]]<ref name="s1"/><ref name="s3"/>
| [[S-Lang (programming language)|S-Lang]]<sup>1,2,3</sub>
|-
| {{Mono|name'''.[{{brackets|'''first'''..;;'''last'''];;'''step'''}}'''}}
| [[Mathematica]],<ref name="s1"/><ref name="s2"/><ref name="s4"/> [[Wolfram Language]]
|-
| {{Mono|name'''{{brackets|'''first''':'''last'''}}'''}}
| [[S-Lang]]<ref name="s1"/><ref name="s2"/><ref name="s3"/>
|-
| {{Mono|name'''.['''first'''..'''step'''..'''last''']'''}}
| [[F Sharp (programming language)|F#]]
|-
| {{Mono|name'''.slice('''first''', '''lastend''')'''}}
| [[Haxe]], [[JavaScript]], [[Scala (programming language)|Scala]]
|-
| {{Mono|name'''array_slice.slice('''name''', '''first''', '''len''')'''}}
| [[PHPCFML]]<sup>4</sub>
|-
| {{Mono|'''array_slice(subseq''' name''', '''first''', end'''len''')'''}}
| [[PHP]]<ref name="s4"/>
| [[Common Lisp programming language|Common Lisp]]
|-
| {{Mono|'''Array.sub(subseq''' name first lenend''')'''}}
| [[Common Lisp]]
|-
| {{Mono|'''(subseq''' name first end''')'''}}
| [[ISLISP]]
|-
| {{Mono|'''Array.sub''' name first len}}
| [[OCaml]]
|-
| {{Mono|'''['''name''' subarrayWithRange:NSMakeRange('''first''', '''len''')]'''}}
| [[Objective-C]] (<code>NSArray *</code> only)
|-
| {{Mono|'''('''first'''([+i.@(-~)'''end'''){'''name}}
| [[J (programming language)|J]]
|-
| {{Mono|name'''['''first'''..<'''end''']'''<br/>name'''['''first'''...'''last''']'''}}
| [[Swift (programming language)|Swift]]
|-
| {{Mono|name '''copyFrom:''' first '''to:'''last<br/>name '''copyFrom:''' first '''count:'''len}}
| [[Smalltalk]]
|-
| {{Mono|name'''['''first'''..'''end''']'''}}
| [[D (programming language)|D]], [[C sharp (programming language)|C#]]<ref name="s5" /><ref name="s6" />
|-
| {{Mono|name'''['''first'''..'''end''']'''<br/>name'''['''first'''..<nowiki>=</nowiki>'''last''']'''}}
| [[Rust (programming language)|Rust]]
|-
| {{Mono|name'''['''first''':'''end''']'''}}
| [[Cobra (programming language)|Cobra]]
|-
| <code>table.move(name, first, last, 1, {})</code>
| [[Lua (programming language)|Lua]]<ref>{{Cite web |title=Lua 5.3 Reference Manual |url=https://www.lua.org/manual/5.3/manual.html#pdf-table.move |access-date=2022-04-02 |website=www.lua.org}}</ref>
|}
 
==Array system cross-reference list==
# Slices for multidimensional arrays are also supported and defined similarly.
<!-- This section is linked from [[array data type|Array]] -->
# Slices of the type <code>''first'':''last'':''step''</code> are also supported.
{| class="sortable wikitable" style="text-align: center;"
# More generally, for 1-d arrays [[Perl]] and [[S-Lang (programming language)|S-Lang]] permit slices of the form <code>''array''[''indices'']</code>, where <code>''indices''</code> an be a range such mentioned in footnote 2 or an explicit list of indices, e.g., '<code>[0,9,3,4]</code>', as well as a combination of the two, e.g., <code>A[[[0:3],7,9,[11:2:-3]]]</code>.
# ''last'' or ''end'' may be a negative number, indicating to stop at the corresponding number of places before the end of the array.
 
==Array system cross-reference list==<!-- This section is linked from [[Array]] -->
{| class="sortable wikitable" style="text-align: center; font-size: smaller;"
|+
! scope="col" | [[Language]]
! [[Programming language]]
! scope="col" | [[Array data type#IndexingIndex origin|Default Base<br>base index]]
! scope="col" | Specifiable<br>index type<ref name="cr16"/>
! Specifiable Index Type<sup>16</sup>
! scope="col" | Specifiable<br>base index
! Specifiable Base Index
! scope="col" | [[Boundsbounds checking|Bound Checkcheck]]
! scope="col" | [[Arrayarray data type#Multi-dimensional arrays|Multidimensional]]
! scope="col" | Dynamically-sized
! scope="col" | [[Arrayarray programming|Vectorized Operationsoperations]]
|-
| [[Ada (programming language)|Ada]]
| style="background:honeydew;" | index type<sup>17<ref name="cr17"/sup>
| style="background:honeydew;" | yes
| style="background:honeydew;" | yes
| style="background:honeydew;" | checked
| style="background:honeydew;" | yes
| style="background:azure;" | init<sup>1<ref name="cr1"/sup>
| style="background:cornsilk;" | some, others definable<sup>5<ref name="cr5"/sup>
|-
| [[ALGOL 68]]
| style="background:azure;" | 1
| style="background:grey80seashell;" | no<sup>25<ref name="cr25"/sub>
| style="background:honeydew;" | yes
| style="background:cornsilk;" | varies
Line 193 ⟶ 365:
| style="background:honeydew;" | yes
| style="background:azure;" | user definable
|-
| [[APL (programming language)|APL]]
| style="background:azure;" | 1
| style="background:grey80;" | ?
| style="background:grey80cornsilk;" | 0 |or ?1<ref name="cr7"/>
| style="background:cornsilk;" | 0 or 1<sup>7</sup>
| style="background:honeydew;" | checked
| style="background:honeydew;" | yes
| style="background:azurehoneydew;" | init<sup>1</sup>yes
| style="background:honeydew;" | yes
|-
| [[assembly languageAWK]]
| style="background:cornsilkazure;" | 01
| style="background:grey80honeydew;" | yes, | ?implicitly
| style="background:seashell;" | no
| style="background:seashell;" | unchecked
| style="background:honeydew;" | yes, as delimited string
| style="background:honeydew;" | yes, rehashed
| style="background:seashell;" | no
|-
| style="background:seashell;" | no
| [[BASIC]]
| style="background:grey80;" | ?
| style="background:cornsilk;" | 0
|-
| [[BASIC programming language|BASIC]]
| style="background:azure;" | 0
| style="background:grey80;" | ?
| style="background:seashell;" | no
| style="background:honeydew;" | checked
| style="background:seashell;" | no
| style="background:azure;" | init<sup>1<ref name="cr1"/sup>
| style="background:grey80;" | ?
|-
| [[C (programming language)|C]]
| style="background:cornsilk;" | 0
| style="background:seashell;" | no
| style="background:seashell;" | no<ref name="cr26"/>
| style="background:seashell;" | unchecked
| style="background:cornsilkhoneydew;" | array of array<sup>2</sup>partially
| style="background:lavender;" | init,<supref name="cr1"/>1,4<ref name="cr4"/sup>, heap<sup>3<ref name="cr3"/sup>
| style="background:seashell;" | no
|-
| [[Ch (computer programming)|Ch]]
| [[C++]]<sup>5</sup>
| style="background:cornsilk;" | 0
| style="background:seashell;" | no
| style="background:seashell;" | no
| style="background:honeydew;" | checked
| style="background:honeydew;" | yes, also array of array<ref name="cr2"/>
| style="background:lavender;" | init,<ref name="cr1"/><ref name="cr4"/> heap<ref name="cr3"/>
| style="background:honeydew;" | yes
|-
| [[C++]]<ref name="cr5"/>
| style="background:cornsilk;" | 0
| style="background:seashell;" | no
| style="background:seashell;" | no<ref name="cr26"/>
| style="background:seashell;" | unchecked
| style="background:cornsilkhoneydew;" | yes, also array of array<sup>2<ref name="cr2"/sup>
| style="background:AliceBlue;" | heap<sup>3<ref name="cr3"/sup>
| style="background:seashell;" | no
|-
Line 242 ⟶ 423:
| style="background:cornsilk;" | 0
| style="background:seashell;" | no
| style="background:seashellcornsilk;" | nopartial<ref name="dotnetarray"/>
| style="background:honeydew;" | checked
| style="background:honeydew;" | yes
| style="background:AliceBlue;" | heap<supref name="cr3"/>3,9<ref name="cr9"/sup>
| style="background:honeydew;" | yes ([[LINQ]] select)
|-
| [[COBOLCFML]]
| style="background:azure;" | 1
| style="background:grey80seashell;" | ?no
| style="background:seashell;" | no
| style="background:honeydew;" | checked
| style="background:honeydew;" | yes, also array of array<ref name="cr2"/>
| style="background:honeydew;" | yes
| style="background:seashell;" | no<sup>14</sup>
|-
| [[COBOL]]
| style="background:azure;" | 1
| style="background:seashell;" | no<ref name="cr27"/>
| style="background:seashell;" | no
| style="background:honeydew;" | checked
| style="background:cornsilk;" | array of array<ref name="cr2"/><ref name="cr28"/>
| style="background:seashell;" | no<ref name="cr14"/>
| style="background:grey80;" | some intrinsics
|-
| [[Cobra (programming language)|Cobra]]
| style="background:cornsilk;" | 0
| style="background:seashell;" | no
| style="background:seashell;" | no
| style="background:honeydew;" | checked
| style="background:cornsilk;" | array of array<ref name="cr2"/>
| style="background:azure;" | heap
| style="background:grey80;" | ?
|-
| [[Common Lisp programming language|Common Lisp]]
| style="background:cornsilk;" | 0
| style="background:grey80;" | ?
| style="background:seashell;" | no
| style="background:honeydew;" | checked<sup>15<ref name="cr15"/sup>
| style="background:honeydew;" | yes
| style="background:honeydew;" | yes
| style="background:honeydew;" | yes (mapcarmap or map-into)
|-
| [[D (programming language)|D]]
| style="background:cornsilk;" | 0
| style="background:grey80honeydew;" | yes<ref>[http://dlang.org/hash-map.html |Associative Arrays - D Programming ?Language]</ref>
| style="background:seashell;" | no
| style="background:cornsilk;" | varies<sup>11<ref name="cr11"/sup>
| style="background:honeydew;" | yes
| style="background:honeydew;" | yes
Line 278 ⟶ 477:
| style="background:cornsilk;" | 0
| style="background:seashell;" | no
| style="background:seashellcornsilk;" | nopartial<ref name="dotnetarray"/>
| style="background:honeydew;" | checked
| style="background:honeydew;" | yes
| style="background:AliceBlue;" | heap<supref name="cr3"/>3,9<ref name="cr9"/sup>
| style="background:seashellhoneydew;" | noyes (map)
|-
| [[FreeBASIC]]
Line 290 ⟶ 489:
| style="background:honeydew;" | checked
| style="background:honeydew;" | yes
| style="background:azure;" | init,<sup>1<ref name="cr1"/sup>, init<sup>21<ref name="cr21"/sup>
| style="background:grey80;" | ?
|-
Line 297 ⟶ 496:
| style="background:honeydew;" | yes
| style="background:honeydew;" | yes
| style="background:cornsilk;" | varies<sup>12<ref name="cr12"/sup>
| style="background:honeydew;" | yes
| style="background:lavender;" | init<sup>1</sup>, heap<sup>3</sup>
| style="background:honeydew;" | yes
| style="background:honeydew;" | yes
|-
|-
| [[FoxPro]]
| style="background:azure;" | 1
Line 310 ⟶ 509:
| style="background:honeydew;" | yes
| style="background:grey80;" | ?
|-
| [[HaskellGo (programming language)|HaskellGo]]
| style="background:grey80cornsilk;" | none (specified on init)0
| style="background:honeydewseashell;" | yes<sup>24</sup>no
| style="background:seashell;" | no
| style="background:honeydew;" | checked
| style="background:cornsilk;" | array of array<ref name="cr2"/>
| style="background:seashell;" | no<ref name="cr29"/>
| style="background:seashell;" | no
|-
| [[Hack (programming language)|Hack]]
| style="background:cornsilk;" | 0
| style="background:honeydew;" | yes
| style="background:honeydew;" | yes
| style="background:honeydew;" | checked
| style="background:honeydew;" | yes
| style="background:honeydew;" | yes
| style="background:honeydew;" | yes
|-
| [[Haskell]]
| style="background:cornsilk;" | 0
| style="background:honeydew;" | yes<ref name="cr24"/>
| style="background:honeydew;" | yes
| style="background:honeydew;" | checked
| style="background:honeydew;" | yes, also array of array<sup>2<ref name="cr2"/sup>
| style="background:azure;" | init<sup>1<ref name="cr1"/sup>
| style="background:grey80;" | ?
|-
| [[IDL (programming language)|IDL]]
| style="background:cornsilk;" | 0
Line 329 ⟶ 546:
| style="background:honeydew;" | yes
|-
| [[ISLISP]]
| [[Java (programming language)|Java]]<sup>5</sup>
| style="background:cornsilk;" | 0
| style="background:grey80;" | ?
| style="background:seashell;" | no
| style="background:honeydew;" | checked
| style="background:honeydew;" | yes
| style="background:honeydew;" | init<ref name="cr1"/>
| style="background:honeydew;" | yes (map or map-into)
|-
| [[J (programming language)|J]]
| style="background:cornsilk;" | 0
| style="background:grey80;" | ?
| style="background:seashell;" | no
| style="background:honeydew;" | checked
| style="background:honeydew;" | yes
| style="background:honeydew;" | yes
| style="background:honeydew;" | yes
|-
| [[Java (programming language)|Java]]<ref name="cr5"/>
| style="background:cornsilk;" | 0
| style="background:seashell;" | no
| style="background:seashell;" | no
| style="background:honeydew;" | checked
| style="background:cornsilk;" | array of array<sup>2<ref name="cr2"/sup>
| style="background:azure;" | init<sup>1<ref name="cr1"/sup>
| style="background:grey80;" | ?
|-
| [[JavaScript]]
| style="background:cornsilk;" | 0
| style="background:grey80seashell;" | no
| style="background:grey80seashell;" | no
| style="background:honeydew;" | checked<sup>22<ref name="cr22"/sup>
| style="background:cornsilk;" | array of array<sup>2<ref name="cr2"/sup>
| style="background:honeydew;" | yes
| style="background:honeydew;" | yes
|-
| [[Julia (programming language)|Julia]]
| style="background:azure;" | 1
| style="background:honeydew;" | yes
| style="background:honeydew;" | yes
| style="background:honeydew;" | checked <small>(can be skipped locally; or globally by user)</small>
| style="background:honeydew;" | yes, also array of array
| style="background:honeydew;" | yes
| style="background:honeydew;" | yes
|-
| [[Lingo (programming language)|Lingo]]
| style="background:azure;" | 1
| style="background:grey80;" | ?
| style="background:grey80;" | ?
| style="background:seashell;" | unchecked
| style="background:honeydew;" | yes
| style="background:honeydew;" | yes
| style="background:honeydew;" | yes
Line 350 ⟶ 603:
| style="background:azure;" | 1
| style="background:grey80;" | ?
| style="background:cornsilk;" | partial<sup>20<ref name="cr20"/sup>
| style="background:honeydew;" | checked
| style="background:cornsilk;" | array of array<sup>2<ref name="cr2"/sup>
| style="background:honeydew;" | yes
| style="background:grey80;" | ?
|-
| [[Mathematica]]
| style="background:azure;" | 1
| style="background:seashell;" | no
| style="background:seashell;" | no
| style="background:honeydew;" | checked
| style="background:honeydew;" | yes
| style="background:honeydew;" | yes
| style="background:honeydew;" | yes
|-
| [[MATLAB]]
| style="background:azure;" | 1
Line 361 ⟶ 623:
| style="background:seashell;" | no
| style="background:honeydew;" | checked
| style="background:honeydew;" | yes<sup>8<ref name="cr8"/sup>
| style="background:honeydew;" | yes
| style="background:honeydew;" | yes
|-
| [[OberonNim (programming language)|OberonNim]]
| style="background:cornsilk;" | 0
| style="background:honeydew;" | yes<ref name="nim-lang.org"/>
| style="background:honeydew;" | yes
| style="background:honeydew;" | optional<ref>{{Cite web|url=https://nim-lang.org/docs/nimc.html|title = Nim Compiler User Guide}}</ref>
| style="background:cornsilk;" | array of array<ref name="cr2"/>
| style="background:honeydew;" | yes
| style="background:honeydew;" | yes<ref>{{Cite web|url=https://stackoverflow.com/questions/53084192/r-style-logical-vector-operation-in-nim|title=Vectorization - R-style logical vector operation in Nim}}</ref>
|-
| [[Oberon (programming language)|Oberon]]
| style="background:cornsilk;" | 0
| style="background:grey80;" | ?
Line 373 ⟶ 644:
| style="background:seashell;" | no
| style="background:grey80;" | ?
|-
| [[Oberon-2]]
| style="background:cornsilk;" | 0
Line 383 ⟶ 654:
| style="background:grey80;" | ?
|-
| [[Objective-C]]<sup>5<ref name="cr5"/sup>
| style="background:cornsilk;" | 0
| style="background:seashell;" | no
| style="background:seashell;" | no
| style="background:honeydew;" | checked
| style="background:cornsilk;" | array of array<sup>2<ref name="cr2"/sup>
| style="background:honeydew;" | yes
| style="background:seashell;" | no
Line 397 ⟶ 668:
| style="background:seashell;" | no
| style="background:honeydew;" | checked by default
| style="background:cornsilk;" | array of array<sup>2<ref name="cr2"/sup>
| style="background:azure;" | init<sup>1<ref name="cr1"/sup>
| style="background:grey80;" | ?
|-
| [[Pascal (programming language)|Pascal]], [[Object Pascal]]
| style="background:honeydew;" | index type<sup>17<ref name="cr17"/sup>
| style="background:honeydew;" | yes
| style="background:honeydew;" | yes
| style="background:cornsilk;" | varies<sup>13<ref name="cr13"/sup>
| style="background:honeydew;" | yes
| style="background:cornsilk;" | varies<sup>10<ref name="cr10"/sup>
| style="background:cornsilk;" | some
|-
| [[Perl]]
| style="background:cornsilk;" | 0
| style="background:seashell;" | no
| style="background:honeydew;" | yes (<code>$[</code>)
| style="background:honeydew;" | checked<sup>22<ref name="cr22"/sup>
| style="background:cornsilk;" | array of array<sup>2<ref name="cr2"/sup>
| style="background:honeydew;" | yes
| style="background:grey80seashell;" | no<sup>18<ref name="cr18"/sup>
|-
| [[Raku (programming language)|Raku]]
| style="background:cornsilk;" | 0
| style="background:seashell;" | no
| style="background:seashell;" | no
| style="background:honeydew;" | checked<ref name="cr22"/>
| style="background:honeydew;" | yes
| style="background:honeydew;" | yes
| style="background:honeydew;" | yes
|-
| [[PHP]]
| style="background:cornsilk;" | 0
| style="background:honeydew;" | yes<sup>23<ref name="cr23"/sup>
| style="background:honeydew;" | yes<sup>23<ref name="cr23"/sup>
| style="background:honeydew;" | checked<sup>23<ref name="cr23"/sup>
| style="background:honeydew;" | yes
| style="background:honeydew;" | yes
| style="background:honeydew;" | yes
|-
| [[PL/I]]
| style="background:grey80azure;" | 1
| style="background:grey80;" | ?
| style="background:honeydew;" | yes
| style="background:honeydew;" | checked
| style="background:grey80;" | yes
| style="background:grey80honeydew;" | noyes
| style="background:grey80honeydew;" | ?optional
| style="background:honeydew;" | yes
|-
| style="background:seashell;" | no
| style="background:grey80;" | yes<ref name="cr30" />
|-
| [[Python (programming language)|Python]]
| style="background:cornsilk;" | 0
Line 442 ⟶ 722:
| style="background:seashell;" | no
| style="background:honeydew;" | checked
| style="background:cornsilk;" | array of array<sup>2<ref name="cr2"/sup>
| style="background:honeydew;" | yes
| style="background:honeydewseashell;" | no<sup>19<ref name="cr19"/sup>
|-
| [[IBM RPG|RPG]]
| style="background:azure;" | 1
| style="background:seashell;" | no
| style="background:seashell;" | no
| style="background:grey80;" | ?
| style="background:seashell;" | no
| style="background:seashell;" | no
| style="background:grey80;" | ?
|-
| [[R (programming language)|R]]
| style="background:azure;" | 1
| style="background:grey80;" | ?
| style="background:seashell;" | no
| style="background:seashell;" | unchecked
| style="background:honeydew;" |yes, also array of array
| style="background:honeydew;" | yes
| style="background:honeydew;" | yes
|-
| [[Ring (programming language)|Ring]]
| style="background:azure;" | 1
| style="background:grey80;" | ?
| style="background:cornsilk;" | partial<ref name="cr20"/>
| style="background:honeydew;" | checked
| style="background:cornsilk;" | array of array<ref name="cr2"/>
| style="background:honeydew;" | yes
| style="background:grey80;" | ?
|-
| [[Ruby (programming language)|Ruby]]
| style="background:cornsilk;" | 0
| style="background:grey80;" | no
| style="background:seashell;" | no
| style="background:honeydewseashell;" | checked<sup>22</sup>no
| style="background:cornsilkhoneydew;" | array of array<sup>2checked<ref name="cr22"/sup>
| style="background:cornsilk;" | array of array<ref name="cr2"/>
| style="background:honeydew;" | yes
| style="background:grey80;" | ?
|-
| [[S-Lang_Rust (programming_languageprogramming language)|S-LangRust]]
| style="background:cornsilk;" | 0
| style="background:seashell;" | no
| style="background:seashell;" | no
| style="background:honeydew;" | checked
| style="background:cornsilk;" | array of array<ref name="cr2"/>
| style="background:grey80;" | no
| style="background:grey80;" | ?
|-
| [[Sass (stylesheet language)|Sass]]
| style="background:azure;" | 1
| style="background:seashell;" | no
| style="background:seashell;" | no
| style="background:honeydew;" | checked
| style="background:cornsilk;" | array of array<ref name="cr2"/>
| style="background:azure;" | init<ref name="cr11"/>
| style="background:grey80;" | ?
|-
| [[S-Lang]]
| style="background:cornsilk;" | 0
| style="background:grey80;" | ?
Line 463 ⟶ 788:
| style="background:honeydew;" | yes
| style="background:honeydew;" | yes
|-
| [[Scala (programming language)|Scala]]
| style="background:cornsilk;" | 0
| style="background:seashell;" | no
| style="background:seashell;" | no
| style="background:honeydew;" | checked
| style="background:cornsilk;" | array of array<ref name="cr2"/>
| style="background:azure;" | init<ref name="cr1"/>
| style="background:honeydew;" | yes (map)
|-
| [[Scheme (programming language)|Scheme]]
| style="background:cornsilk;" | 0
Line 469 ⟶ 803:
| style="background:seashell;" | no
| style="background:honeydew;" | checked
| style="background:cornsilk;" | array of array<sup>2<ref name="cr2"/sup>
| style="background:azure;" | init<sup>1<ref name="cr1"/sup>
| style="background:grey80honeydew;" | yes | ?(map)
|-
| [[Smalltalk]]<sup>5<ref name="cr5"/sup>
| style="background:azure;" | 1
| style="background:grey80;" | ?
| style="background:seashell;" | no
| style="background:honeydew;" | checked
| style="background:cornsilk;" | array of array<sup>2<ref name="cr2"/sup>
| style="background:honeydew;" | yes<sup>6<ref name="cr6"/sup>
| style="background:grey80;" | ?
|-
| [[Swift (programming language)|Swift]]
| [[Visual Basic]]
| style="background:azurecornsilk;" | 0
| style="background:seashell;" | no
| style="background:seashell;" | no
| style="background:honeydew;" | checked
| style="background:cornsilk;" | array of array<ref name="cr2"/>
| style="background:honeydew;" | yes
| style="background:grey80;" | ?
|-
| [[Visual Basic (classic)]]
| style="background:honeydew;" | 0, 1, or index type<ref name="msbasicarrays"/>
| style="background:seashell;" | no
| style="background:honeydew;" | yes
Line 491 ⟶ 834:
| style="background:grey80;" | ?
|-
| [[Visual Basic (.NET)]]
| style="background:cornsilkhoneydew;" | 0 or index type<ref name="msbasicarrays"/>
| style="background:seashell;" | no
| style="background:seashell;" | no
| style="background:cornsilk;" | partial<ref name="dotnetarray"/>
| style="background:honeydew;" | checked
| style="background:honeydew;" | yes
| style="background:honeydew;" | yes
| style="background:honeydew;" | yes ([[LINQ]] select)
|-
| [[Wolfram Language]]
| style="background:azure;" | 1
| style="background:seashell;" | no
| style="background:seashell;" | no
| style="background:honeydew;" | checked
| style="background:honeydew;" | yes
| style="background:honeydew;" | yes
| style="background:honeydew;" | yes
|-
| [[Windows PowerShell]]
| style="background:cornsilk;" | 0
Line 508 ⟶ 860:
| style="background:honeydew;" | heap
| style="background:grey80;" | ?
|-
|-class="sortbottom"
| [[Xojo]]
! [[Programming language]]
| style="background:cornsilk;" | 0
! [[Array#Indexing|Default Base index]]
| style="background:seashell;" | no
! Specifiable Index Type<sup>16</sup>
| style="background:seashell;" | no
! Specifiable Base Index
| style="background:honeydew;" | checked
! [[Bounds checking|Bound Check]]
| style="background:honeydew;" | yes
! [[Array#Multi-dimensional arrays|Multidimensional]]
| style="background:honeydew;" | yes
! Dynamically-sized
| style="background:seashell;" | no
! [[Array programming|Vectorized Operations]]
|-
| [[XPath]]/[[XQuery]]
| style="background:azure;" | 1
| style="background:seashell;" | no
| style="background:seashell;" | no
| style="background:honeydew;" | checked
| style="background:cornsilk;" | array of array<ref name="xpath"/><ref name="cr2"/>
| style="background:honeydew;" | yes
| style="background:honeydew;" | yes
|}
<div style="font-size: 90%;">
# 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 assembler) 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, but is set for a whole "workspace".
# At least 2 dimensions (scalar numbers are 1×1 arrays, vectors are 1×n or n×1 arrays).
# Allows creation of fixed-size arrays in "unsafe" code, allowing for enhanced [[interoperability]] with other languages
# Varies by implementation. Newer implementations (FreePascal and Delphi) permit heap-based dynamic arrays.
# Behaviour can be tuned using compiler switches. As in DMD 1.0 bounds are checked in debug mode and unchecked in release mode for efficiency reasons.
# Almost all Fortran implementations offer bounds checking options via compiler switches. However by default, bounds checking is usually turned off for efficiency reasons.
# Many implementations (Turbo Pascal, Delphi, FreePascal) 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 (programming language)|Perl]] array data types do not support vectorized operations as defined here. However, the [[PerlDL]] extension adds array objects with this capability.
# The standard [[Python (programming language)|Python]] array type, <code>list</code>, does not support vectorized operations as defined here. However, the [[numpy]] extension adds array objects with this capability.
# 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 this language, you 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 in order 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 you to use any type which is an instance of Ix as index type. So you can define a custom type and use it 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 INT. However a hash function could be used to convert other types to INT. eg. name'''['''hash("string")''']'''
</div>
 
== 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 [[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
y = sin (x)
 
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. As an example,
<syntaxhighlight lang="fortran">
even = x(2::2);
odd = x(::2);
</syntaxhighlight>
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 ===
{| class="wikitable" style="white-space:nowrap;"
! scope="col" | Language/<br>Library
! scope="col" | Create
! scope="col" | [[Determinant]]
! scope="col" | [[Transpose]]
! scope="col" | Element
! scope="col" | Column
! scope="col" | Row
! scope="col" | [[Eigenvalues]]
|-
| [[APL (programming language)|APL]]
| {{code|2=apl|m←dims⍴x11 x12 ...}}
| {{code|2=apl|-.×m}}
| {{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<br/>{{code|2=apl|j⌷⍤1⊢m}} or {{code|2=apl|j⌷⍉m}}
| {{code|2=apl|m[i;]}} or {{code|2=apl|i⌷m}}
| {{code|2=apl|⌹⍠1⊢m}}
|-
| [[Fortran]]
| {{code|1=m = RESHAPE([x11, x12, ...], SHAPE(m))}}
|
| {{code|TRANSPOSE(m)}}
| {{code|m(i,j)}}
| {{code|m(:,j)}}
| {{code|m(i,:)}}
|
|-
| [[Ch (computer programming)|Ch]]<ref>[http://www.softintegration.com/products/features/ch_vs_matlab.html Ch numerical features]</ref>
| {{code|1=m = {...}}}
| {{code|determinant(m)}}
| {{code|transpose(m)}}
| {{code|m[i-1][j-1]}}
| {{code|shape(m,0)}}
| {{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]]
| <syntaxhighlight lang="nb" inline>{{x11, x12, ...}, ...}</syntaxhighlight>
| {{code|Det[m]}}
| {{code|Transpose[m]}}
| {{code|m[[i,j]]}}
| {{code|m[[;;,j]]}}
| {{code|m[[i]]}}
| {{code|Eigenvalues[m]}}
|-
| [[MATLAB]] /<br/>[[GNU Octave]]
| {{code|1=m = [...]}}
| {{code|det(m)}}
| {{code|m.'}}
| {{code|m(i,j)}}
| {{code|m(:,j)}}
| {{code|m(i,:)}}
| {{code|eig(m)}}
|-
| [[NumPy]]
| {{code|1=m = mat(...)}}
| {{code|linalg.det(m)}}
| {{code|m.T}}
| {{code|m[i-1,j-1]}}
| {{code|m[:,j-1]}}
| {{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]]
| {{code|1=m = reshape([x11, x12, ...], [new-dims])}}
|
| {{code|1=m = transpose(m)}}
| {{code|m[i,j]}}
| {{code|m[*,j]}}
| {{code|m[j,*]}}
|
|-
| [[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()}}
|-
|}
 
== References ==
 
{{Reflist|refs=
<ref name="indexing">The index may be a negative number, indicating the corresponding number of places before the end of the array.</ref>
 
<ref name="s1">Slices for multidimensional arrays are also supported and defined similarly.</ref>
Some scripting languages such as [[IDL]], [[MATLAB]], and [[S-Lang (programming language)|S-Lang]] have
<ref name="s2">Slices of the type <code>''first'':''last'':''step''</code> are also supported.</ref>
native support for vectorized operations on arrays. For example, to
<ref name="s3">More generally, for 1-d arrays [[Perl]] and [[S-Lang]] allow slices of the form<code>''array''[''indices'']</code>, where <code>''indices''</code> can be a range such mentioned in footnote 2 or an explicit list of indices, e.g., '<code>[0,9,3,4]</code>', or a mix of both, e.g., <code>A[[[0:3]],7,9,[11:2:-3]]]</code>.</ref>
perform an element by element sum of two arrays, ''a'' and ''b'' to
<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>
produce a third ''c'', it is only necessary to write
<ref name="s5">[[C Sharp (programming language)|C#]] 8.0 proposed feature ({{as of|2019|08|29|lc=y}})</ref>
<pre>
<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>
c = a + b
</pre>
Since the implicit inner loops do not occur at the level of the
interpreter, the speed of such vectorized operations can be as fast as
compiled code. 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
<pre>
y = sin (x)
</pre>
will result in an array ''y'' whose elements are sine of the
corresponding elements of the array ''x''.
 
<ref name="cr1">Size can only be chosen on initialization after which it is fixed.</ref>
Vectorized index operations are also supported. As an example,
<ref name="cr2">Allows arrays of arrays which can be used to emulate most—but not all—aspects multi-dimensional arrays</ref>
<pre>
<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>
even = x[[0::2]];
<ref name="cr4">C99 allows for variable size arrays; however there is almost no compiler available to support this new feature</ref>
odd = x[[1::2]];
<ref name="cr5">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</ref>
</pre>
<ref name="cr6">The class Array is fixed-size, but OrderedCollection is dynamic</ref>
is how one would use [[S-Lang_(programming_language)|S-Lang]] create arrays from the even and odd
<ref name="cr7">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|⍠}}).</ref>
elements of an array. Another common use of vectorized indices is a
<ref name="cr8">At least 2 dimensions (scalar numbers are 1×1 arrays, vectors are 1×n or n×1 arrays).</ref>
filtering operation. Consider a clipping operation of a sine wave
<ref name="cr9">Allows creating fixed-size arrays in "unsafe" code, allowing enhanced [[interoperability]] with other language</ref>
where amplitudes larger than 0.5 are to be set to 0.5. Using
<ref name="cr10">Varies by implementation. Newer implementations ([[Free Pascal]], [[Object Pascal]] ([[Delphi (software)|Delphi]])) allow heap-based dynamic arrays.</ref>
[[S-Lang (programming language)|S-Lang]], this may accomplished by
<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>
<pre>
<ref name="cr12">Almost all Fortran implementations offer bounds checking options via compiler switches. However by default, bounds checking is usually turned off for efficiency</ref>
y = sin(x);
<ref name="cr13">Many implementations ([[Turbo Pascal]], [[Object Pascal]] ([[Delphi (software)|Delphi]]), [[Free Pascal]]) allow the behaviour to be changed by compiler switches and in-line directives</ref>
y[where(abs(y)>0.5)] = 0.5;
<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>
</pre>
<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. However, the [[Perl Data Language]] extension adds array objects with this ability.</ref>
<ref name="cr19">The standard [[Python (programming language)|Python]] array type, <code>list</code>, does not support vectorized operations as defined here. However, the [[numpy]] extension adds array objects with this ability</ref>
<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. Arrays declared with no index range are created as variable-length arrays, while arrays with a declared range are created as fixed-length arrays</ref>
<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 to decide to grow the array, and you do not have unsafe memory access like you do in C.</ref>
<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}}. e.g. {{Mono|name'''['''hash("string")''']'''}}</ref>
<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}}} or {{Mono|[1,2,3]}} which can.</ref>
<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>
}}
 
[[Category:Arrays|Programming language comparison]]
[[Category:Programming language comparisons|*Array]]