Creating an Array: Difference between revisions

m
Switch to header template
(→‎[[Java]]: Use Java header instead)
m (Switch to header template)
Line 4:
In this task, the goal is to create an [[array]]. Mention if the [[array base]] begins at a number other than zero.
 
==[[{{header|ActionScript]]}}==
[[Category:ActionScript]]
// ActionScript arrays are zero-based
//
Line 17 ⟶ 16:
var v:Array = [1,2,3];
 
==[[{{header|Ada]]}}==
[[Category:Ada]]
'''Compiler:''' GCC 4.1.2
 
Line 34 ⟶ 32:
This_Week : Daily_Activities := (Mon..Fri => Work, Others => Fish);
 
==[[{{header|AppleScript]]}}==
[[Category:AppleScript]]
 
AppleScript arrays are called lists:
set empty to {}
Line 44 ⟶ 40:
set any to {1, "foo", 2.57, missing value, ints}
 
==[[{{header|BASIC]]}}==
[[Category:BASIC]]
'''Interpeter:''' [[QuickBasic]] 4.5, PB 7.1
 
Line 61 ⟶ 56:
myArray(1,2) = "Item2"
 
==[[{{header|C]]}}==
[[Category:C]]
'''Compiler:''' GCC, MSVC, BCC, Watcom
 
Line 120 ⟶ 114:
myArray5.Add(2);
 
==[[{{header|C sharp|C#]]}}==
[[Category:C sharp]]
Example of array of 10 int types:
 
Line 148 ⟶ 141:
string[,] funny_matrix = new string[2,2]{ {"clowns", "are"} , {"not", "funny"} };
 
==[[{{header|Clean]]}}==
[[Category:Clean]]
Array denotations are overloaded in Clean, therefore we explicitly specify the types. There are lazy, strict, and unboxed array.
===Lazy array===
Line 170 ⟶ 162:
array = {x \\ x <- ['a' .. 'z']}
 
==[[{{header|ColdFusion]]}}==
[[Category:ColdFusion]]
Creates a one-dimensional Array
<cfset arr1 = ArrayNew(1)>
Line 180 ⟶ 171:
''ColdFusion Arrays are '''NOT''' zero-based, they begin at index '''1'''''
 
==[[{{header|Common Lisp]]}}==
[[Category:Common Lisp]]
Creates a one-dimensional array of length 10. The initial contents are undefined.
(make-array 10)
Line 189 ⟶ 179:
(make-array 4 :element-type 'integer :initial-contents '(1 2 3 4) :adjustable t)
 
==[[{{header|D]]}}==
[[Category:D]]
'''Compiler:''' [[DMD]],[[GDC]]
 
Line 199 ⟶ 188:
int[5] = [0,1,2,3,4];
 
==[[{{header|E]]}}==
[[Category:E]]
 
[] # immutable, empty
[1,9,17] # immutable, 3 elements
Line 207 ⟶ 194:
[].diverge(int) # mutable, integers only
 
==[[{{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.
 
Line 230 ⟶ 215:
0 to MyArray
 
==[[{{header|Fortran]]}}==
[[Category:Fortran]]
 
Default case:
 
Line 248 ⟶ 231:
 
 
==[[{{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.
 
Line 274 ⟶ 255:
String[] s = {"hello" , "World" };
 
==[[{{header|JavaScript]]}}==
[[Category:JavaScript]]
var myArray = new Array();
var myArray2 = new Array("Item1","Item2");
Line 283 ⟶ 263:
10 myArray :array
 
==[[{{header|MAXScript]]}}==
[[Category:MAXScript]]
'''Interpreter:''' [[3D Studio Max]] 8
myArray = #()
myArray2 = #("Item1", "Item2")
 
==[[{{header|mIRC Scripting Language]]}}==
[[Category:mIRC Scripting Language]]
'''Interpeter:''' mIRC Script Editor
'''Libraries:''' [[mArray Snippet]]
alias creatmearray { .echo -a $array_create(MyArray, 5, 10) }
 
==[[{{header|OCaml]]}}==
[[Category:OCaml]]
Using an array literal:
 
Line 312 ⟶ 289:
 
 
==[[{{header|Perl]]}}==
[[Category:Perl]]
'''Interpreter:''' [[Perl]] 5
 
Line 345 ⟶ 321:
[qw(! $ %
 
==[[{{header|Pop11]]}}==
[[Category:Pop11]]
 
Pop11 distinguishes between vectors and arrays. Vectors are one
dimensional and the lowest index is 1. There is special shorthand
Line 366 ⟶ 340:
vars a1 = newarray([2 5 -1 1], 0);
 
==[[{{header|Python]]}}==
[[Category:Python]]
 
List are mutable arrays. You can put anything into a list, including other lists.
 
Line 401 ⟶ 373:
</pre>
 
==[[{{header|Raven]]}}==
[[Category:Raven]]
 
[ 1 2 3.14 'a' 'b' 'c' ] as a_list
a_list print
Line 415 ⟶ 385:
5 => "c"
 
==[[{{header|Ruby]]}}==
[[Category:Ruby]]
I've used the same examples as the Python-example above.
.
Line 426 ⟶ 395:
anything = [1, 'foo', 2.57, zeros]
 
==[[{{header|Toka]]}}==
[[Category:Toka]]
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