Comments (21)
Why not simply 4.0's fn:characters("abcdefghijklmnopqrstuvwxyz")
? Highly customizable, and transparent.
from qtspecs.
Perhaps what we're searching for is a syntax like
$value[# RANGE #]
where
(a) If $value is an array, it operates on the array; if it is a string, it operates on the string; if it is a sequence (that is, any other sequence), it operates on the sequence.
(b) The syntax of RANGE allows us to select at least (i) any single item, (ii) any contiguous subsequence, (iii) any set of single items.
from qtspecs.
This digressed into a discussion of using operators such as [] to slice into a string. That's beyond the scope of the original issue. Having introduced char() taking a numeric argument, I don't think there's any further obvious improvement on the table, so I propose closing the issue with no further action.
from qtspecs.
I'm not convinced we need to provide anything new here.
Firstly, I'm not sure what you want the semantics of ('a' to 'z') to be. You seem to be suggesting that you want all single Unicode characters whose codepoints are in this range, but you also hint that you might want single-character Unicode strings that are >= 'a' and <= 'z' in some collation (which is a different requirement), or that you might want all Unicode characters in some character category.
If the actual requirement is for unicode characters whose codepoints are in a range, then I think the expression provided is the right way to go. If that's a surrogate for some other requirement, then perhaps we need something new. For example we could certainly consider unicode-category('Latin') to return all characters in a unicode category or block.
from qtspecs.
In addition, we could allow both integers and strings as argument for fn:char
, to be able to write…
(65 to 90) ! fn:char(.)
Otherwise, people may be tempted to write…
(65 to 90) ! fn:char(`#{ . }`)
from qtspecs.
Yes, allowing an integer argument to fn:char seems reasonable.
from qtspecs.
Just out of curiosity: Can we cast a string to a sequence (or an array) of single-character strings?
In C# a string is also an array of its characters and one simply writes myString[3]
without any casts and this produces (a Char) the 4-th character of myString
.
This is very convenient and it would be great to have something similar in XPath.
Maybe we could introduce a char
type in XPath?
from qtspecs.
@dnovatchev see, new in 4.0, fn:characters
from qtspecs.
We introduced the fn:characters()
function to allow a string to be treated as a sequence of characters. Implicit casting to a sequence wouldn't work because a string is already a sequence of length 1.
from qtspecs.
i’m not sure this is easily discoverable.
Making features "discoverable" is not something the specifications can do on their own; and there is always a problem that the more features we pack into the language, the harder it is for users to discover that they exist. We can do a fair bit by presenting examples of use cases, but in the end, the languages specs are a specification, not a user guide.
from qtspecs.
We introduced the
fn:characters()
function to allow a string to be treated as a sequence of characters. Implicit casting to a sequence wouldn't work because a string is already a sequence of length 1.
Yes, but what I am proposing is not "implicit casting to a sequence".
It is implicit casting to an array.
We could even decide not to define such casting at all, just simply say that:
"abcdefgh"[3]
is a shorthand for:
subsring("abcdefgh", 3, 1)
This is extremely nice and convenient - proven by my experience.
Easy to remember and use, twice shorter, less moving parts and much less error prone than the result of extending this shortcut.
from qtspecs.
"abcdefgh"[3]
This expression, unfortunately, is legal since XPath 2.0, and returns an empty sequence.
A potentially viable alternative is to allow
"abcde"[1 ...]
"abcde"[2 ... 4]
"abcde"[3 ... 3]
"abcde"[... 3]
from qtspecs.
"abcdefgh"[3]
This expression, unfortunately, is legal since XPath 2.0, and returns an empty sequence.
A potentially viable alternative is to allow
"abcde"[1 ...] "abcde"[2 ... 4] "abcde"[3 ... 3] "abcde"[... 3]
I think we could do even better:
"abcd"(3)
And certainly, instead of using
substring("abcdefg", 2, 3)
We could have:
"abcde"[2 ... 4]
from qtspecs.
"abcd(3)"
Probably "abcd"(3)
?
"abcde"[2 ... 4]
What would (1 to 3, "abcde")[2 ... 4]
yield?
from qtspecs.
"abcd(3)"
Probably
"abcd"(3)
?
Yes, thanks for catching this. Corrected in the referred-to comment.
"abcde"[2 ... 4]
What would
(1 to 3, "abcde")[2 ... 4]
yield?
2, "abcde"
from qtspecs.
What would
(1 to 3, "abcde")[2 ... 4]
yield?
2, "abcde"
Thanks. What would be the rules that lead to this result?
from qtspecs.
What would
(1 to 3, "abcde")[2 ... 4]
yield?
2, "abcde"
Thanks. What would be the rules that lead to this result?
Sorry again. The result should be:
2, 3, "abcde"
The rules are that we have the sequence:
(1, 2, 3, "abcde")
And the deconstructor [2 ... 4]
selects its subsequence starting with the second item and ending at the 4th item.
from qtspecs.
And the deconstructor
[2 ... 4]
selects its subsequence starting with the second item and ending at the 4th item.
Would ("abcde", 1 to 3)[2 ... 4]
return 1, 2, 3
or "b", "c", "d"
?
from qtspecs.
And the deconstructor
[2 ... 4]
selects its subsequence starting with the second item and ending at the 4th item.Would
("abcde", 1 to 3)[2 ... 4]
return1, 2, 3
or"b", "c", "d"
?
1, 2, 3
from qtspecs.
$value[# RANGE #]
I assume it wouldn't be much shorter than
items-at($value, RANGE) (: or :)
RANGE ! get($value, .)
Personally, I’d still be in favor of having $value[RANGE]
.
from qtspecs.
Perhaps what we're searching for is a syntax like
$value[# RANGE #]
Could be even:
$value # RANGE #
or
$value <- RANGE
from qtspecs.
Related Issues (20)
- XQFO Code in the Rules sections HOT 7
- fn:subsequence-where: equivalent `fn:slice` expression HOT 2
- Reinstate subsequence-before HOT 1
- regular expressions - whitespace HOT 6
- regular expression addition - word boundaries HOT 1
- How to invert a predicate function HOT 16
- QT4CG-064-03, QT4CG-064-04: Examples, Return type of `fallback`
- fn:transform() improvements
- [XSLT] Need to say what happens when a capturing accumulator rule matches a non-element node HOT 4
- Predicates, sequences of numbers: Feedback HOT 2
- Identify optional arguments in callback functions HOT 41
- Add position argument to scan-left and scan-right HOT 3
- fn:reduce (or fn:fold without initial value) HOT 5
- Numeric Comparisons HOT 8
- Transitive closure on non-nodes HOT 2
- Invisible-xml - missing details HOT 1
- Invoking maps & arrays: allow sequences? HOT 5
- regular expression addition - lookbehind assertions and lookahead assertions HOT 2
- regular expression addition - comments 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 qtspecs.