Skip to content
Surf Wiki
Save to docs
general/arrays

From Surf Wiki (app.surf) — the open knowledge base

Comparison of programming languages (array)

List of programming language comparisons


Summary

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.

LanguagesSizeFirstLast
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)
{{Mononame.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.

FormatLanguages
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
orEiffel

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)
FormatLanguages
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
{{Mononame**first..[Swift
Smalltalk
D, C#
Rust
Cobra
`table.move(name, first, last, 1, {})`Lua

Array system cross-reference list

LanguageDefault
base indexSpecifiable
index typeSpecifiable
base indexBound checkMultidimensionalDynamically-sizedVectorized operations
Adaindex typeyesyescheckedyesinitsome, others definable
ALGOL 681noyesvariesyesyesuser definable
APL1?0 or 1checkedyesyesyes
AWK1yes, implicitlynouncheckedyes, as delimited stringyes, rehashedno
BASIC0?nocheckednoinit?
C0nonouncheckedpartiallyinit, heapno
Ch0nonocheckedyes, also array of arrayinit, heapyes
C++0nonouncheckedyes, also array of arrayheapno
C#0nopartialcheckedyesheapyes (LINQ select)
CFML1nonocheckedyes, also array of arrayyesno
COBOL1nonocheckedarray of arraynosome intrinsics
Cobra0nonocheckedarray of arrayheap?
Common Lisp0?nocheckedyesyesyes (map or map-into)
D0yesnovariesyesyes?
F#0nopartialcheckedyesheapyes (map)
FreeBASIC0noyescheckedyesinit, init?
Fortran1yesyesvariesyesyesyes
FoxPro1?nocheckedyesyes?
Go0nonocheckedarray of arraynono
Hack0yesyescheckedyesyesyes
Haskell0yesyescheckedyes, also array of arrayinit?
IDL0?nocheckedyesyesyes
ISLISP0?nocheckedyesinityes (map or map-into)
J0?nocheckedyesyesyes
Java0nonocheckedarray of arrayinit?
JavaScript0nonocheckedarray of arrayyesyes
Julia1yesyeschecked (can be skipped locally; or globally by user)yes, also array of arrayyesyes
Lingo1??uncheckedyesyesyes
Lua1?partialcheckedarray of arrayyes?
Mathematica1nonocheckedyesyesyes
MATLAB1?nocheckedyesyesyes
Nim0yesyesoptionalarray of arrayyesyes
Oberon0?nocheckedyesno?
Oberon-20?nocheckedyesyes?
Objective-C0nonocheckedarray of arrayyesno
OCaml0nonochecked by defaultarray of arrayinit?
Pascal, Object Pascalindex typeyesyesvariesyesvariessome
Perl0noyes (`$`)checkedarray of arrayyesno
[Raku0nonocheckedyesyesyes
PHP0yesyescheckedyesyesyes
PL/I1yesyesoptionalyesnoyes
Python0nonocheckedarray of arrayyesno
RPG1nono?nono?
R1?nouncheckedyes, also array of arrayyesyes
Ruby0nonocheckedarray of arrayyes?
Rust0nonocheckedarray of arrayno?
Sass1nonocheckedarray of arrayinit?
S-Lang0?nocheckedyesyesyes
Scala0nonocheckedarray of arrayinityes (map)
Scheme0?nocheckedarray of arrayinityes (map)
Smalltalk1?nocheckedarray of arrayyes?
Swift0nonocheckedarray of arrayyes?
Visual Basic (classic)0, 1, or index typenoyescheckedyesyes?
Visual Basic (.NET)0 or index typenopartialcheckedyesyesyes (LINQ select)
Wolfram Language1nonocheckedyesyesyes
Windows PowerShell0nonocheckedyesheap?
Xojo0nonocheckedyesyesno
XPath/XQuery1nonocheckedarray of arrayyesyes

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,

FORTRAN
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/
LibraryCreateDeterminantTransposeElementColumnRowEigenvalues
APLoror or
oror
Fortran
Ch}
Julia and its standard library
oror
Mathematica /
Wolfram Language{{x11, x12, ...}, ...}
MATLAB /
GNU Octave
NumPy
R{{code1=m
S-Lang
SymPy

References

References

  1. "Programming in Lua : 11.1".
  2. "Nim Tutorial (Part I)".
  3. "Eiffeldoc : ARRAY".
  4. "Lua 5.3 Reference Manual".
  5. [http://dlang.org/hash-map.html Associative Arrays - D Programming Language]
  6. "Nim Compiler User Guide".
  7. "Vectorization - R-style logical vector operation in Nim".
  8. [http://www.softintegration.com/products/features/ch_vs_matlab.html Ch numerical features]
  9. The index may be a negative number, indicating the corresponding number of places before the end of the array.
  10. Slices for multidimensional arrays are also supported and defined similarly.
  11. Slices of the type ''first'':''last'':''step'' are also supported.
  12. 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]]].
  13. {{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.
  14. [[C Sharp (programming language). C#]] 8.0 proposed feature ({{as of. 2019. 08. 29
  15. "Ranges - C# 8.0 language proposals". Microsoft.
  16. Size can only be chosen on initialization after which it is fixed.
  17. Allows arrays of arrays which can be used to emulate most—but not all—aspects multi-dimensional arrays
  18. 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.
  19. C99 allows for variable size arrays; however there is almost no compiler available to support this new feature
  20. 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
  21. The class Array is fixed-size, but OrderedCollection is dynamic
  22. 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. ⍠).
  23. At least 2 dimensions (scalar numbers are 1×1 arrays, vectors are 1×n or n×1 arrays).
  24. Allows creating fixed-size arrays in "unsafe" code, allowing enhanced [[interoperability]] with other language
  25. Varies by implementation. Newer implementations ([[Free Pascal]], [[Object Pascal]] ([[Delphi (software). Delphi]])) allow heap-based dynamic arrays.
  26. 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
  27. Almost all Fortran implementations offer bounds checking options via compiler switches. However by default, bounds checking is usually turned off for efficiency
  28. Many implementations ([[Turbo Pascal]], [[Object Pascal]] ([[Delphi (software). Delphi]]), [[Free Pascal]]) allow the behaviour to be changed by compiler switches and in-line directives
  29. 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
  30. Most Common Lisp implementations allow checking to be selectively disabled
  31. 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]]
  32. The default base index is the lowest value of the index type used
  33. 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.
  34. 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
  35. 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.
  36. 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
  37. 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.
  38. 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"
  39. 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
  40. 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")''']'''
  41. 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.
  42. COBOL arrays may be indexed with "INDEX" types, distinct from integer types
  43. 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
  44. 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.
  45. Size can be chosen when the array is declared, or when it is allocated, after which it is fixed.
  46. 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.
  47. 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.
  48. 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).
Wikipedia Source

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.

Want to explore this topic further?

Ask Mako anything about Comparison of programming languages (array) — get instant answers, deeper analysis, and related topics.

Research with Mako

Free with your Surf account

Content sourced from Wikipedia, available under CC BY-SA 4.0.

This 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