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)


include ..\Utilitys.pmt
 
0 tolist            /# create an empty array/list. '( )' is equivalent #/
drop                /# remove top of the stack #/
0 10 repeat         /# put an array/list of 10 elements (each element has value 0) to the stack #/
flush               /# remove all elements. List is empty [] #/
drop
( 1 2 "Hello" pi )  /# put an initialize array/list to stack #/
-7 1 set            /# modified first element to -7 #/
0 get               /# get the last element. '-1 get' is equivalent #/
drop
( "next" "level" ) 2 put    /# insert a list in a list = [-7, ["next", "level"], 2, "Hello", 3.141592653589793]] #/ 
3 2 slice           /# extract the subarray/sublist [ 2 "Hello" ] #/
 
pstack              /# show the content of the stack #/ 