Like all other values, arrays are immutable. For example, the <code>[[Array Module#array:reverse|array:reverse]]</code> function creates a new array containing a re-ordering of the members of an existing array, but the existing array is not changed by the operation. Like sequences, arrays have no identity. It is meaningful to compare the contents of two arrays, but there is no way of asking whether they are "the same array": two arrays with the same content are indistinguishable.
===Atomization===
If an array is ''atomized'', all of its members will be atomized. As a result, an atomized item may now result in more than one item. Some examples:
<pre class="brush:xquery">
fn:data([1 to 2]) (: returns the sequence 1, 2 :)
[ 'a', 'b', 'c' ] = 'b' (: returns true :)
<a>{ [ 1, 2 ] }</a> (: returns <a>1 2</a> :)
array { 1 to 2 } + 3 (: error: the left operand returns two items :)
</pre>
Atomization also applies to function arguments. The following query returns 5, because the array will be atomized to a sequence of 5 integers:
<pre class="brush:xquery">
let $f := function($x as xs:integer*) { count($x) }
return $f([1 to 5])
</pre>
However, the next query returns 1, because the array is already of the general type {{Code|item()}}, and no atomization will take place:
<pre class="brush:xquery">
let $f := function($x as item()*) { count($x) }
return $f([1 to 5])
</pre>
Arrays can be compared with the {{Code|fn:deep-equal}} function. The [[Array Module]] describes the available set of array functions.
==Lookup Operator==
The syntax makes nested function calls more readable, as it is easy to see if parentheses are balanced.
===Atomization===
If an array is ''atomized'', all of its members will be atomized. As a result, an atomized item may now result in more than one item. Some examples:
<pre class="brush:xquery">
fn:data([1 to 2]) (: returns the sequence 1, 2 :)
[ 'a', 'b', 'c' ] = 'b' (: returns true :)
<a>{ [ 1, 2 ] }</a> (: returns <a>1 2</a> :)
array { 1 to 2 } + 3 (: error: the left operand returns two items :)
</pre>
Atomization also applies to function arguments. The following query returns 5, because the array will be atomized to a sequence of 5 integers:
<pre class="brush:xquery">
let $f := function($x as xs:integer*) { count($x) }
return $f([1 to 5])
</pre>
However, the next query returns 1, because the array is already of the general type {{Code|item()}}, and no atomization will take place:
<pre class="brush:xquery">
let $f := function($x as item()*) { count($x) }
return $f([1 to 5])
</pre>
Arrays can be compared with the {{Code|fn:deep-equal}} function. The [[Array Module]] describes the available set of array functions.
==Functions==