probably a bug
Thursday, 2 September 2021 · 3 messages
RS
Rob Stapper2 Sep 2021 17:22 #
Hi Cristian,
Consider snippets [1] and [2], both result in false(). That can’t be right to me.
[1] () = 4
[2] () != 4
Rob.
Sent from Mail for Windows
--
This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus
MH
Martin Honnen2 Sep 2021 17:30 #
Quoted text · Rob Stapper · 7 lines
On 02.09.2021 17:22, Rob Stapper wrote: > Consider snippets [1] and [2], both result in false(). That can’t be > right to me. > > [1] () = 4 > > [2] () != 4
The empty sequence is neither equal to nor unequal to the number 4 as it doesn't contain any item to compare 4 to:
https://www.w3.org/TR/xquery-31/#id-general-comparisons
General comparisons are existentially quantified comparisons that may be applied to operand sequences of any length.
The result of the comparison is true if and only if there is a pair of atomic values, one in the first operand sequence and the other in the second operand sequence, that have the required magnitude relationship. Otherwise the result of the comparison is false.
LQ
Quoted text · Rob Stapper · 9 lines
On Thu, 2021-09-02 at 17:22 +0200, Rob Stapper wrote: > Hi Cristian, > > Consider snippets [1] and [2], both result in false(). That can’t be > right to me. > > [1] () = 4 > [2] () != 4 >
[1] means, there is an item in the left sequence whose atomized value is equal to some value on the right.
There isn't, so it's false.
[2] means, there's some item on the left whose value is unequal to some value on the right.
hence, (1, 2, 3) != (1, 2, 3) is true because for example 1 onthe left is != to 2 on the right. Since there is no such pair of items here the result is false.
!= is almost never useful - it doesn't do what most people expect, and was included in XPath 1 for completeness.
Use not($seq1 = $seq2) for more sanity, or use eq and ne for singletons.
Liam
--
Liam Quin, https://www.delightfulcomputing.com/
Available for XML/Document/Information Architecture/XSLT/
XSL/XQuery/Web/Text Processing/A11Y training, work & consulting. Barefoot Web-slave, antique illustrations: http://www.fromoldbooks.org
Written for BaseX 9.6. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery