Arrays: Difference between revisions

no edit summary
No edit summary
Line 2,300:
b = [1, 2, 3]
</lang>
 
=={{header|Futhark}}==
 
Multidimensional regular arrays are a built-in datatype in Futhark. They can be written as array literals:
 
<lang Futhark>
[1, 2, 3]
</lang>
 
Or created by an assortment of built-in functions:
 
<lang Futhark>
replicate 5 3 == [3,3,3,3,3]
iota 5 = [0,1,2,3,4]
</lang>
 
Uniqueness types are used to permit in-place updates without violating referential transparency. For example, we can write a function that writes an element to a specific index of an array as such:
 
<lang Futhark>
fun update(as: *[]int, i: int, x: int): []int =
let as[i] = x
in x
</lang>
 
Semantically the <code>update</code> function returns a new array, but the compiler is at liberty to re-use the memory where array <code>as</code> is stored, rather than create a copy as is normally needed in pure languages. Whenever the compiler encounters a call <code>update(as,i,x)</code>, it checks that the <code>as</code> is not used again. This prevents the in-place update from being observable, except through the return value of <code>modify</code>.
 
=={{header|Gambas}}==
Anonymous user