-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fn:boolean: EBV support for more item types #829
Comments
My vote would go for making no change to the EBV rules. I think it's better that we require users to spell out exactly what condition they want to test for. |
@ChristianGruen It is not clear with the proposed EBV rules what would be the value of Could you, please, explain? As for the boolean value of empty maps or arrays, we actually need functions: |
You're welcome: |
Another user feedback, just from today, referred to the missing EBV support for dates (“ I checked what different processors report back for
I still believe the list of supported types is very arbitrary: Can we give a convincing answer why e.g. URIs are supported, but why QNames, dates, binary data, etc. are rejected? |
The "convincing answer" is that the mechanism was invented in XPath 1.0 whose type system was strongly based on Javascript as defined in 1999, and as the type system grew larger (a) extending EBV to cover additional types would have involved many arbitrary decisions that users would find hard to remember, and (b) the Javascript community had itself discovered that the equivalent of EBV (truthy and falsy values) was proving a major nightmare, resulting in the introduction of new operators like "===" with stricter semantics, and general advice that good coding practice was to steer clear of the whole area. Consider arrays. Is there any serious chance we will get the WG to agree what the EBVs of |
What I can observe is (based on the feedback we got over the last years) that the status quo is not satisfying, and I believe it’s exactly because the current language still “smells like XPath 1.0”, and something that was forgotten later on. I would see no reason to push this further without the historical aspect, but now that we have a rather arbitrary situation, I believe we should at least try to do justice to the existence of the other data types.
I would still hope so; that’s why I presented two options in the initial comment, and I would like to have a vote on them. My favorite would now be Option 1, i.e., doing what JavaScript does – your remark that XPath 1.0 was inspired by JavaScript underlines this – and return |
I don't remember having Javascript in mind back in 1999. We needed numbers and strings and booleans so we got those. We needed other things too, but the goals were less ambitious (or differently ambitious maybe). I don't think we'd be making user's lives more difficult if we said the EBV of anything not currently covered was equivalent to ~exists()`. But I almost never try to write code that relies on it, so I don't feel strongly about it. |
When it comes to clean and usable design, JavaScript probably doesn’t stand a chance against Python, so if we don’t necessarily take JS as our reference, we could also choose a smarter approach. The mere existence of different solutions shouldn't deter us from choosing our own solution. If people consider the JS equivalent of EBVs to be a nightmare, the question is why we advocate their usage in our spec at all. Do we generally believe it’s a concept that people users rely on? If yes, we should build on it. If no, we should say so in the spec and update the code examples in question to use explicit boolean comparisons. |
The CG decided to close this issue without any further action at meeting 069. |
In #817, it was discussed that the current EBV semantics have been inspired a lot by XPath 1.0. Today, we have numerous other data types apart from strings, doubles, booleans, and nodes, and I believe it’s time to do justice to this by getting rid of the error for unsupported data types for
fn:boolean
.We currently have:
node()
true()
xs:boolean
$item != 0 and not(is-NaN($item))
xs:untypedAtomic
,xs:string
,xs:anyURI
$item != ''
I have two options in mind:
true()
for all other items. This would allow us to do simple checks like:array(*)
array:size($item) != 0
map(*)
map:size($item) != 0
xs:base64Binary
xs:hex64Binary
bin:length($item) != 0
ornot($item = (xs:hexBinary(''), xs:base64Binary(''))
It would then be possible to write:
if($map)
instead ofmap:size($map) != 0
ormap:exists($map)
(see #827 for the naming controversy).Note that
if($map)
will also returnfalse()
is$map
is an empty sequence.if($func) { $func(1, 2) }
instead ofexists($func)
In the last comments of #817, it was addressed that the behavior of existing code may change if errors are replaced by results. I hope we can live with that, as I cannot think of cases in which the EBV computation make sense for items that always raise an error.
Which option do some of you prefer?
The text was updated successfully, but these errors were encountered: