[Bug 26958] On not precluding updates in XQuery 3.1

https://www.w3.org/Bugs/Public/show_bug.cgi?id=26958

--- Comment #16 from Jonathan Robie <jonathan.robie@gmail.com> ---
(In reply to Michael Kay from comment #14)
> I do not want F+O discussions of operators such as map:merge to contain any
> mention of concepts like "copying" a map or array. It's a meaningless
> concept at that level. 

They already do that, and even specify most of the details.  For instance:

<quote>
17.1.1 map:merge
Creates a new map that combines entries from a number of existing maps.
</quote>

<quote>
17.1.8 map:remove
Constructs a new map by removing an entry from an existing map
</quote>

Sometimes this is a little confused:

<quote>
17.1.6 map:put
Creates a map that adds a single entry to an existing map, or replaces a single
entry in an existing map.
</quote>

Does it really "replace a single entry in an existing map", or does it create a
new map? Later text clarifies that a new map is created.

<quote>
The function map:put returns a new ·map· The new map contains all entries from
the supplied $map, with the exception of any entry whose key is $key, together
with a new entry whose key is $key and whose associated value is $value.
</quote>

> Specs should be testable, and there is no way of
> testing whether map:merge has copied a map or array or not, therefore the
> spec should have nothing to say on the subject. 

I believe the above assertions are testable without updates.  The level of
clarity we need for updates is also needed for these functions.

For instance, variable references clearly show us whether a new copy has been
made by map:merge, map:put, or map:remove. Some examples:

declare variable $element := <e/>;
declare variable $map := map { "one" : 1, "two" : 2 }
declare variable $array := [ 1, 2 ]

* Query 1 - identity of elements placed in a map

let $map1 := map { "value" : 1, "map" : $map, "array" : $array, "element" :
$element }
let $map2 := map { "value" : 1, "map" : $map, "array" : $array, "element" :
$element }
return $map1("element") is $map2("element")

If this returns 'true', then we have the same element in each case, and the map
constructor does not create a new node with a new identity, as element
constructors do.

* Query 2 - does map:put return a new map or not?

let $map1 := map { "value" : 1, "map" : $map, "array" : $array, "element" :
$element }
let $map2 := map:put($map1, "color", "white")
return $map1("color")

The reference to $map1 shows that $map2 is not a modified copy of $map1, but a
new map.

* Query 3 - does map:merge return a new map or not?

let $map1 := map { "value" : 1, "map" : $map, "array" : $array, "element" :
$element }
let $map2 := map:merge($map1, map:entry("color", "white"))
return $map1("color")

The reference to $map1 shows that $map2 is not a modified copy of $map1, but a
new map.

* Query 4 - does map:remove return a new map or not?

let $map1 := map { "value" : 1, "map" : $map, "array" : $array, "element" :
$element }
let $map2 := map:remove($map1, "value") 
return $map1("value")

The reference to $map1 shows that $map2 is not a modified copy of $map1, but a
new map.

-- 
You are receiving this mail because:
You are the QA Contact for the bug.

Received on Tuesday, 4 November 2014 20:57:57 UTC