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)


 
needs array'
 
( Create an array with four elements )
^array'new{ 1 2 3 4 } constant a
 
( Add 10 to each element in an array and update the array with the results )
a [ 10 + ] ^array'map
 
( Apply a quote to each element in an array; leaves the contents alone )
a [ 10 + putn cr ] ^array'apply
 
( Display an array )
a ^array'display
 
( Look for a value in an array )
3 a ^array'in?
6 a ^array'in?
 
( Look for a string in an array )
"hello" a ^array'stringIn?
 
( Reverse the order of items in an array )
a ^array'reverse
 
( Append two arrays and return a new one )
^array'new{ 1 2 3 } constant a
^array'new{ 4 5 6 } constant b
a b ^array'append constant c
 
( Create an array from the values returned by a quote )
[ 1 2 "hello" "world" ] ^array'fromQuote constant d
 
( Create a quote from the values in an array )
d ^array'toQuote
 