Creating an Array: Difference between revisions

added standard ml
m (→‎{{header|Smalltalk}}: creation (move the rest to the other task))
(added standard ml)
Line 473:
 
let array = [| 1; 2; 3; 4; 5 |];;
 
Converting from a list:
 
let array = Array.of_list some_list
 
To create an array of five elements with the value 0:
Line 709 ⟶ 713:
in particular SmallInteger"
array at: 2 put: 100.</lang>
 
=={{header|Standard ML}}==
Converting from a list:
 
val array = Array.fromList [1,2,3,4,5]
 
To create an array of five elements with the value 0:
 
val num_items = 5 and initial_value = 0;
val array = Array.array (num_items, initial_value)
 
To create an array with contents defined by passing each index to a callback (in this example, the array is set to the squares of the numbers 0 through 4):
 
fun callback index = index * index;
val array = Array.tabulate (5, callback)
 
In addition to arrays, the Standard ML library also has "vectors", which are immutable arrays. Most implementations support the following syntax for a vector literal, although it is not standard:
 
val vector = #[1,2,3,4,5]
 
=={{header|Tcl}}==
Anonymous user