Comments (7)
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.
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.
from xpath-ng.
from xpath-ng.
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.
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.
(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)
- Compatibility between implementations HOT 5
- Provide a combined grammar and grammar checker
- Provide a QT3 style test file for each proposal? HOT 2
- Propose an Enumeration Type HOT 1
- Propose Type Aliases HOT 4
- Propose several CSS Selector style shorthands (first-child, last-child, etc.) HOT 3
- Reducing proliferation of function namespaces HOT 5
- Expression for exploding "complex atomics" to maps HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xpath-ng.