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.
==
// ActionScript arrays are zero-based
//
Line 17 ⟶ 16:
var v:Array = [1,2,3];
==
'''Compiler:''' GCC 4.1.2
Line 34 ⟶ 32:
This_Week : Daily_Activities := (Mon..Fri => Work, Others => Fish);
==
AppleScript arrays are called lists:
set empty to {}
Line 44 ⟶ 40:
set any to {1, "foo", 2.57, missing value, ints}
==
'''Interpeter:''' [[QuickBasic]] 4.5, PB 7.1
Line 61 ⟶ 56:
myArray(1,2) = "Item2"
==
'''Compiler:''' GCC, MSVC, BCC, Watcom
Line 120 ⟶ 114:
myArray5.Add(2);
==
Example of array of 10 int types:
Line 148 ⟶ 141:
string[,] funny_matrix = new string[2,2]{ {"clowns", "are"} , {"not", "funny"} };
==
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']}
==
Creates a one-dimensional Array
<cfset arr1 = ArrayNew(1)>
Line 180 ⟶ 171:
''ColdFusion Arrays are '''NOT''' zero-based, they begin at index '''1'''''
==
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)
==
'''Compiler:''' [[DMD]],[[GDC]]
Line 199 ⟶ 188:
int[5] = [0,1,2,3,4];
==
[] # immutable, empty
[1,9,17] # immutable, 3 elements
Line 207 ⟶ 194:
[].diverge(int) # mutable, integers only
==
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
==
Default case:
Line 248 ⟶ 231:
==
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" };
==
var myArray = new Array();
var myArray2 = new Array("Item1","Item2");
Line 283 ⟶ 263:
10 myArray :array
==
'''Interpreter:''' [[3D Studio Max]] 8
myArray = #()
myArray2 = #("Item1", "Item2")
==
'''Interpeter:''' mIRC Script Editor
'''Libraries:''' [[mArray Snippet]]
alias creatmearray { .echo -a $array_create(MyArray, 5, 10) }
==
Using an array literal:
Line 312 ⟶ 289:
==
'''Interpreter:''' [[Perl]] 5
Line 345 ⟶ 321:
[qw(! $ %
==
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);
==
List are mutable arrays. You can put anything into a list, including other lists.
Line 401 ⟶ 373:
</pre>
==
[ 1 2 3.14 'a' 'b' 'c' ] as a_list
a_list print
Line 415 ⟶ 385:
5 => "c"
==
I've used the same examples as the Python-example above.
.
Line 426 ⟶ 395:
anything = [1, 'foo', 2.57, zeros]
==
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
|