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
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.
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
basex-talk@mailman.uni-konstanz.de