Giter Site home page Giter Site logo

Comments (2)

michaelhkay avatar michaelhkay commented on June 19, 2024

The reason I left out numeric subscripting is that it's not clear whether it should return a single member or an array of members.

You would probably expect

let $array := [1, 2, 3, 4, 5] return $array?[3]

to return 3 rather than [3].

Overloading filtering and subscripting works for sequences because an item is the same thing as a sequence of length 1. That equivalence doesn't exist for arrays, so if you overload the operator there's immense scope for confusion.

As the spec says:

Unlike filter expressions for sequences, there is no special treatment of numeric predicate values. This is because it would be unclear whether such an expression should return the member at the specified position, or a singleton array containing that member. Numeric values for the predicate are disallowed to avoid any possible confusion.

from qtspecs.

ChristianGruen avatar ChristianGruen commented on June 19, 2024

Unlike filter expressions for sequences, there is no special treatment of numeric predicate values. This is because it would be unclear whether such an expression should return the member at the specified position, or a singleton array containing that member. Numeric values for the predicate are disallowed to avoid any possible confusion.

Iโ€™ve seen the comment, but I donโ€™t find it persuasive. [$n] and [position() = $n] have always been equivalent; if we believe that this syntax could be immensely confusing for arrays and possibly maps, we should definitely drop positional access in array/map predicates in general. Next, now that we allow EXPR[$n1, $n2, ...], the single integer is just a special case.

My preference, however, would be to make predicates completely symmetric, no matter if they are part of XPath steps, Filter Expressions or Array/Map Filters.

from qtspecs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.