Semantics of = and !=

后端 未结 2 1629
慢半拍i
慢半拍i 2021-01-21 01:43

In XQuery,

(\"foo\", \"bar\") = (\"foo\", \"bar\")

yields the value true. That seems obvious. But I noticed that

(         


        
相关标签:
2条回答
  • 2021-01-21 02:14

    This can be found in the documentation for XQuery under section "3.5.2 General Comparisons".

    The following example contains two general comparisons, both of which are true. This example illustrates the fact that the = and != operators are not inverses of each other.

    (1, 2) = (2, 3)
    (1, 2) != (2, 3)
    

    Reading into the reasoning, it reads to me as if the rules of Atomization are to blame here. If the elements are untypedAtomic, then the parser is free to "guess" at how the comparison should be made which allows for the difference in operations based on the elements themselves rather than on any operator behavior.

    0 讨论(0)
  • 2021-01-21 02:22

    XQuery = and != are existential operators. They yield true if any element in the left set together with any element in the right set would return true for this operator (so actually same semantics for =, !=, >, ... - all the comparison operators without alphabetical characters).

    ("foo", "bar") != ("foo", "bar")
    

    "foo" on the left side is != "bar" on the right side, so the whole comparison is true.

    You probably want to use deep-equal for the equals-comparison and its negated version for the not-equals-comparison as you already proposed in your question.

    0 讨论(0)
提交回复
热议问题