Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arrays and maps: consistency #1871

Open
ChristianGruen opened this issue Mar 13, 2025 · 2 comments
Open

Arrays and maps: consistency #1871

ChristianGruen opened this issue Mar 13, 2025 · 2 comments
Labels
Enhancement A change or improvement to an existing feature Propose for V4.0 The WG should consider this item critical to 4.0 XQFO An issue related to Functions and Operators

Comments

@ChristianGruen
Copy link
Contributor

ChristianGruen commented Mar 13, 2025

Suggestions (based on #1338, related: #1868)

  1. In symmetry with the pairs lookup specifier, we should add array:pairs and an inverse array:of-pairs function.
  2. In symmetry with the values lookup specifier, we should add array:values and map:values functions, to retrieve the values of maps and the members of arrays in a sequence of arrays.
  3. In return, array:members and array:of-members seem redundant, and we should drop them.
  4. In analogy with the keys specifier and map:keys, we should add array:keys (which returns a dense integer range).

Background

With version 4.0, we are adding a lot of promising and powerful new map and array features. This is a big step forward, compared to the obvious limitations of 3.1.

Some aspects of the 3.1 design have made it difficult (or impossible) to fully adjust array and maps, but (in my opinion) the old overall concept was impressively consistent – and it is definitely a big challenge to achieve a 4.0 design that is not too fragmented.

To me, this becomes particularly evident in the case of arrays. The following example sums up the items of all members of an array. For the cumbersome 3.1 solution…

for $pos in 1 to array:size($array)
return sum($array($pos))

…we now have several (roughly?) equivalent options to do this:

  1. for member $m in $array return sum($m)
  2. array:members($array) ! sum(?value)
  3. $array?pairs::* ! sum(?value)
  4. $array?values::* ! sum(.)

The examples above imply that:

  • for 1., an array member is a sequence;
  • for 2., an array member is a map;
  • for 3., an array has pairs (but there is no array:pairs);
  • for 4., an array has values (but there is no array:values).
@ChristianGruen ChristianGruen added Enhancement A change or improvement to an existing feature Propose for V4.0 The WG should consider this item critical to 4.0 XQFO An issue related to Functions and Operators labels Mar 13, 2025
@dnovatchev
Copy link
Contributor

Suggestions (based on #1338, related: #1868)

  1. In symmetry with the pairs lookup specifier, we should add array:pairs and an inverse array:of-pairs function.

We already have the numbered-item record which serves exactly this purpose (the mentioned above array:pairs). Therefore, in order to avoid clutter and pollution, we could reuse this record and have: array:numbered-items, and array:from-numbered-items

  1. In symmetry with the values lookup specifier, we should add array:values and map:values functions, to retrieve the values of maps and the members of arrays in a sequence of arrays.
  1. In return, array:members and array:of-members seem redundant, and we should drop them.
  1. In analogy with the keys specifier and map:keys, we should add array:keys (which returns a dense integer range).

This seems quite unnecessary, because we already have array:size. If it was allowed to have any integer as the first and last index of an array, then a useful function would be array:bounds

@ChristianGruen
Copy link
Contributor Author

Note that the main intent of this issue is consistency, i.e. to bring maps and arrays closer together, and to align array terminology with the key specifiers of the lookup operator, which allows you to retrieve “pairs”, “keys” and “values” of arrays (see https://qt4cg.org/specifications/xquery-40/xpath-40.html#id-postfix-lookup).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement A change or improvement to an existing feature Propose for V4.0 The WG should consider this item critical to 4.0 XQFO An issue related to Functions and Operators
Projects
None yet
Development

No branches or pull requests

2 participants