Giter VIP home page Giter VIP logo

Comments (7)

michaelhkay avatar michaelhkay commented on July 21, 2024

And then a corresponding function array:slice().

For definitional purposes I'm wondering about defining operations like slice, subsequence, remove, reverse, insert-before in terms of corresponding operations on arrays, so fn:slice($seq, $range) is defined as array:slice(array{$seq}, $range)?*.s

A difficulty with this is the different conventions for handling "index out of bounds" conditions.

from xpath-ng.

benibela avatar benibela commented on July 21, 2024

I'm proposing an extension to range expressions so you can do

0 by 2 to 10 => 0,2,4,6,8,10

That by could be defined as a filtering operator

  0 to 10 by 2 => (0 to 10) by 2 => 0,2,4,6,8,10

As such it could work with all sequences

  ("a", "b", "c", "d", "e") by 1 => ("a", "b", "c", "d", "e")
  ("a", "b", "c", "d", "e") by 2 => ("a", "c", "e")
  ("a", "b", "c", "d", "e") by 3 => ("a", "d")
  ("a", "b", "c", "d", "e") by 4 => ("a", "e")
  ("a", "b", "c", "d", "e") by 5 => ("a")

And then a slice() function so that

Or in the filter expression

 (A,B,C,D,E)[3, 4, 5] => C,D, E
 (A,B,C,D,E)[3 to 5] => C,D, E
 (A,B,C,D,E)[1 to 5 by 2 ] => A, C, E

the different conventions for handling "index out of bounds" conditions.

have been an extraordinary bad idea from the beginning

from xpath-ng.

michaelhkay avatar michaelhkay commented on July 21, 2024

from xpath-ng.

michaelhkay avatar michaelhkay commented on July 21, 2024

from xpath-ng.

rhdunn avatar rhdunn commented on July 21, 2024

I personally find 1 to 10 by 2 easier to read than 1 by 2 to 10, that is -- define the range, then the step. The former is also the way other languages like Scala define the ordering.

Other than that, I'm in favour of this extension.

from xpath-ng.

benibela avatar benibela commented on July 21, 2024

That gets quite messy in edge cases especially where the expression used in the predicate is context-dependent, and can yield either a boolean or a number. It would be a natural if we didn't already have the difficult overloading of A[B] to do both filtering and subscripting.

I have argued for these things before

There I wrote A[B] could mean A[let $b := B return if (count($b) le 1 or head($b) instance of node()) then $b else position() = $b ]

Or perhaps A[ position() = B[. instance of xs:numeric] or B[not(. instance of xs:numeric)] ] would be more intuitive (but a bigger change, since it would treat [(1, <x/>)] as [true()])

You have to ask what expressions like //empl[1 to xs:integer(@height)] are supposed to mean. Or for that matter, //empl[1 to position()]. It might be doable, but the rules would certainly be complicated.

//empl[1 to position()] simply would return everything

//empl[1 to xs:integer(@height)] would probably be //empl[position() <= xs:integer(@height)]

from xpath-ng.

benibela avatar benibela commented on July 21, 2024

(10 to 1) is an empty sequence, so ((10 to 1) by -1) would still be an empty sequence if "by" is a binary operator.

Perhaps by with negative number could be defined to reverse the sequence

Then 1 to 10 by -1 would be descending

from xpath-ng.

Related Issues (9)

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.