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)


[1] (define a (make-vector 10)) ; vector of 10 elements initialized to the empty list
 
A
[2] (define b (make-vector 10 5)) ; vector of 10 elements initialized to 5
 
B
[3] (define c #(1 2 3 4 5 6 7 8 9 10)) ; vector literal
 
C
[4] (vector-ref c 3) ; retrieve a value -- NB. indexed from 0
 
4
[5] (vector-set! a 5 1) ; set a_5 to 1
 
1
[6] (define d (make-array 5 6 7)) ; 3-dimensional array of size 5 by 6 by 7
 
D
[7] (array-set! d 1 2 3 10) ; set d_1,2,3 to 10 -- NB. still indexed from 0
 
10
[8] (array-ref d 1 2 3) ; and get the value of d_1,2,3
 
10