Giter Site home page Giter Site logo

Comments (21)

Arithmeticus avatar Arithmeticus commented on July 18, 2024 2

Why not simply 4.0's fn:characters("abcdefghijklmnopqrstuvwxyz")? Highly customizable, and transparent.

from qtspecs.

michaelhkay avatar michaelhkay commented on July 18, 2024 1

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.

See also issues #149 and #816

from qtspecs.

michaelhkay avatar michaelhkay commented on July 18, 2024 1

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.

michaelhkay avatar michaelhkay commented on July 18, 2024

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.

ChristianGruen avatar ChristianGruen commented on July 18, 2024

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.

michaelhkay avatar michaelhkay commented on July 18, 2024

Yes, allowing an integer argument to fn:char seems reasonable.

from qtspecs.

dnovatchev avatar dnovatchev commented on July 18, 2024

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.

Arithmeticus avatar Arithmeticus commented on July 18, 2024

@dnovatchev see, new in 4.0, fn:characters

from qtspecs.

michaelhkay avatar michaelhkay commented on July 18, 2024

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.

michaelhkay avatar michaelhkay commented on July 18, 2024

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.

dnovatchev avatar dnovatchev commented on July 18, 2024

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.

michaelhkay avatar michaelhkay commented on July 18, 2024

"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.

dnovatchev avatar dnovatchev commented on July 18, 2024

"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.

ChristianGruen avatar ChristianGruen commented on July 18, 2024

"abcd(3)"

Probably "abcd"(3) ?

"abcde"[2 ... 4]

What would (1 to 3, "abcde")[2 ... 4] yield?

from qtspecs.

dnovatchev avatar dnovatchev commented on July 18, 2024

"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.

ChristianGruen avatar ChristianGruen commented on July 18, 2024

What would (1 to 3, "abcde")[2 ... 4] yield?

2, "abcde"

Thanks. What would be the rules that lead to this result?

from qtspecs.

dnovatchev avatar dnovatchev commented on July 18, 2024

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.

ChristianGruen avatar ChristianGruen commented on July 18, 2024

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.

dnovatchev avatar dnovatchev commented on July 18, 2024

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"?

1, 2, 3

from qtspecs.

ChristianGruen avatar ChristianGruen commented on July 18, 2024
$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.

dnovatchev avatar dnovatchev commented on July 18, 2024

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)

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.