This task is about arrays.

For hashes or associative arrays, please see Creating an Associative Array.

For a definition and in-depth discussion of what an array is, see Array.



Task

Show basic array syntax in your language.

Basically, create an array, assign a value to it, and retrieve an element   (if available, show both fixed-length arrays and
dynamic arrays, pushing a value into it).

Please discuss at Village Pump:   Arrays.

Please merge code in from these obsolete tasks:

   Creating an Array
   Assigning Values to an Array
   Retrieving an Element of an Array


Related tasks

   Collections
   Creating an Associative Array
   Two-dimensional array (runtime)


use "assert"      // due to the use of Fact
 
- - -
 
var numbers = Array[I32](16) // creating array of 32-bit ints with initial allocation for 16 elements
numbers.push(10) // add value 10 to the end of array, extending the underlying memory if needed
try
  let x = numbers(0) // fetch the first element of array. index starts at 0
  Fact(x == 10)      // try block is needed, because both lines inside it can throw exception
end
 
var other: Array[U64] = [10, 20, 30] // array literal
let s = other.size() // return the number of elements in array
try
  Fact(s == 3)  // size of array 'other' is 3
  other(1) = 40 // 'other' now is [10, 40, 30]
end