Creating an Array: Difference between revisions

Content added Content deleted
(→‎[[Java]]: Use Java header instead)
m (Switch to header template)
Line 4: Line 4:
In this task, the goal is to create an [[array]]. Mention if the [[array base]] begins at a number other than zero.
In this task, the goal is to create an [[array]]. Mention if the [[array base]] begins at a number other than zero.


==[[ActionScript]]==
=={{header|ActionScript}}==
[[Category:ActionScript]]
// ActionScript arrays are zero-based
// ActionScript arrays are zero-based
//
//
Line 17: Line 16:
var v:Array = [1,2,3];
var v:Array = [1,2,3];


==[[Ada]]==
=={{header|Ada}}==
[[Category:Ada]]
'''Compiler:''' GCC 4.1.2
'''Compiler:''' GCC 4.1.2


Line 34: Line 32:
This_Week : Daily_Activities := (Mon..Fri => Work, Others => Fish);
This_Week : Daily_Activities := (Mon..Fri => Work, Others => Fish);


==[[AppleScript]]==
=={{header|AppleScript}}==
[[Category:AppleScript]]

AppleScript arrays are called lists:
AppleScript arrays are called lists:
set empty to {}
set empty to {}
Line 44: Line 40:
set any to {1, "foo", 2.57, missing value, ints}
set any to {1, "foo", 2.57, missing value, ints}


==[[BASIC]]==
=={{header|BASIC}}==
[[Category:BASIC]]
'''Interpeter:''' [[QuickBasic]] 4.5, PB 7.1
'''Interpeter:''' [[QuickBasic]] 4.5, PB 7.1


Line 61: Line 56:
myArray(1,2) = "Item2"
myArray(1,2) = "Item2"


==[[C]]==
=={{header|C}}==
[[Category:C]]
'''Compiler:''' GCC, MSVC, BCC, Watcom
'''Compiler:''' GCC, MSVC, BCC, Watcom


Line 120: Line 114:
myArray5.Add(2);
myArray5.Add(2);


==[[C sharp|C#]]==
=={{header|C sharp|C#}}==
[[Category:C sharp]]
Example of array of 10 int types:
Example of array of 10 int types:


Line 148: Line 141:
string[,] funny_matrix = new string[2,2]{ {"clowns", "are"} , {"not", "funny"} };
string[,] funny_matrix = new string[2,2]{ {"clowns", "are"} , {"not", "funny"} };


==[[Clean]]==
=={{header|Clean}}==
[[Category:Clean]]
Array denotations are overloaded in Clean, therefore we explicitly specify the types. There are lazy, strict, and unboxed array.
Array denotations are overloaded in Clean, therefore we explicitly specify the types. There are lazy, strict, and unboxed array.
===Lazy array===
===Lazy array===
Line 170: Line 162:
array = {x \\ x <- ['a' .. 'z']}
array = {x \\ x <- ['a' .. 'z']}


==[[ColdFusion]]==
=={{header|ColdFusion}}==
[[Category:ColdFusion]]
Creates a one-dimensional Array
Creates a one-dimensional Array
<cfset arr1 = ArrayNew(1)>
<cfset arr1 = ArrayNew(1)>
Line 180: Line 171:
''ColdFusion Arrays are '''NOT''' zero-based, they begin at index '''1'''''
''ColdFusion Arrays are '''NOT''' zero-based, they begin at index '''1'''''


==[[Common Lisp]]==
=={{header|Common Lisp}}==
[[Category:Common Lisp]]
Creates a one-dimensional array of length 10. The initial contents are undefined.
Creates a one-dimensional array of length 10. The initial contents are undefined.
(make-array 10)
(make-array 10)
Line 189: Line 179:
(make-array 4 :element-type 'integer :initial-contents '(1 2 3 4) :adjustable t)
(make-array 4 :element-type 'integer :initial-contents '(1 2 3 4) :adjustable t)


==[[D]]==
=={{header|D}}==
[[Category:D]]
'''Compiler:''' [[DMD]],[[GDC]]
'''Compiler:''' [[DMD]],[[GDC]]


Line 199: Line 188:
int[5] = [0,1,2,3,4];
int[5] = [0,1,2,3,4];


==[[E]]==
=={{header|E}}==
[[Category:E]]

[] # immutable, empty
[] # immutable, empty
[1,9,17] # immutable, 3 elements
[1,9,17] # immutable, 3 elements
Line 207: Line 194:
[].diverge(int) # mutable, integers only
[].diverge(int) # mutable, integers only


==[[Forth]]==
=={{header|Forth}}==
[[Category:Forth]]

Forth has a variety of ways to allocate arrays of data, though it has no built-in array handling words, favoring pointer manipulation.
Forth has a variety of ways to allocate arrays of data, though it has no built-in array handling words, favoring pointer manipulation.


Line 230: Line 215:
0 to MyArray
0 to MyArray


==[[Fortran]]==
=={{header|Fortran}}==
[[Category:Fortran]]

Default case:
Default case:


Line 248: Line 231:




==[[IDL]]==
=={{header|IDL}}==
[[Category:IDL]]

IDL doesn't really distinguish between scalars and arrays - the same operations that can create the one can <i>usually</i> create the other as well.
IDL doesn't really distinguish between scalars and arrays - the same operations that can create the one can <i>usually</i> create the other as well.


Line 274: Line 255:
String[] s = {"hello" , "World" };
String[] s = {"hello" , "World" };


==[[JavaScript]]==
=={{header|JavaScript}}==
[[Category:JavaScript]]
var myArray = new Array();
var myArray = new Array();
var myArray2 = new Array("Item1","Item2");
var myArray2 = new Array("Item1","Item2");
Line 283: Line 263:
10 myArray :array
10 myArray :array


==[[MAXScript]]==
=={{header|MAXScript}}==
[[Category:MAXScript]]
'''Interpreter:''' [[3D Studio Max]] 8
'''Interpreter:''' [[3D Studio Max]] 8
myArray = #()
myArray = #()
myArray2 = #("Item1", "Item2")
myArray2 = #("Item1", "Item2")


==[[mIRC Scripting Language]]==
=={{header|mIRC Scripting Language}}==
[[Category:mIRC Scripting Language]]
'''Interpeter:''' mIRC Script Editor
'''Interpeter:''' mIRC Script Editor
'''Libraries:''' [[mArray Snippet]]
'''Libraries:''' [[mArray Snippet]]
alias creatmearray { .echo -a $array_create(MyArray, 5, 10) }
alias creatmearray { .echo -a $array_create(MyArray, 5, 10) }


==[[OCaml]]==
=={{header|OCaml}}==
[[Category:OCaml]]
Using an array literal:
Using an array literal:


Line 312: Line 289:




==[[Perl]]==
=={{header|Perl}}==
[[Category:Perl]]
'''Interpreter:''' [[Perl]] 5
'''Interpreter:''' [[Perl]] 5


Line 345: Line 321:
[qw(! $ %
[qw(! $ %


==[[Pop11]]==
=={{header|Pop11}}==
[[Category:Pop11]]

Pop11 distinguishes between vectors and arrays. Vectors are one
Pop11 distinguishes between vectors and arrays. Vectors are one
dimensional and the lowest index is 1. There is special shorthand
dimensional and the lowest index is 1. There is special shorthand
Line 366: Line 340:
vars a1 = newarray([2 5 -1 1], 0);
vars a1 = newarray([2 5 -1 1], 0);


==[[Python]]==
=={{header|Python}}==
[[Category:Python]]

List are mutable arrays. You can put anything into a list, including other lists.
List are mutable arrays. You can put anything into a list, including other lists.


Line 401: Line 373:
</pre>
</pre>


==[[Raven]]==
=={{header|Raven}}==
[[Category:Raven]]

[ 1 2 3.14 'a' 'b' 'c' ] as a_list
[ 1 2 3.14 'a' 'b' 'c' ] as a_list
a_list print
a_list print
Line 415: Line 385:
5 => "c"
5 => "c"


==[[Ruby]]==
=={{header|Ruby}}==
[[Category:Ruby]]
I've used the same examples as the Python-example above.
I've used the same examples as the Python-example above.
.
.
Line 426: Line 395:
anything = [1, 'foo', 2.57, zeros]
anything = [1, 'foo', 2.57, zeros]


==[[Toka]]==
=={{header|Toka}}==
[[Category:Toka]]
Toka allows creation of an array using is-array. Access to the elements is done using
Toka allows creation of an array using is-array. Access to the elements is done using
get-element, put-element, get-char-element, and put-char-element functions. You can
get-element, put-element, get-char-element, and put-char-element functions. You can