metaeducation / rebol-issues

6 stars 1 forks source link

EXCLUDE incorrect on negated bitsets #2371

Open hostilefork opened 5 years ago

hostilefork commented 5 years ago

The NEGATE operation on bitsets does not actually invert the bits, but sets a flag on the bitset indicating that search answers should be negated:

>> bits-two: make bitset! [2]
== make bitset! #{20}

>> find bits-two 1
== none

>> find bits-two 2
== true

>> bits-not-two: negate bits-two
== make bitset! [not bits #{20}]

>> find bits-not-two 1
== true

>> find bits-not-two 2 
== none

But if you try to exclude 1 from the negated bitset, you get an answer that acts as if you hadn't been asking it on a negated bitset:

>> bits-nothing: exclude bits-not-two make bitset! [1]
== make bitset! #{20}

>> find bits-nothing 1
== none

>> find bits-nothing 2
== true

The code doesn't honor the negation bit, so all it did was clear it on the result...and clear out 1 (that wasn't there in the data being negated), leaving the 2.

Red has a similar problem, but thinks the bitset is #{60) as a result of the exclusion.

hostilefork commented 5 years ago

This is discussed and commented on in this blog entry: http://www.rebol.net/r3blogs/0114.html

"Furthermore, we will need to consider the various results of logical operations performed on bitsets, including AND, OR, XOR, but also UNION, INTERSECT, DIFFERENCE, and EXCLUDE. These become just a bit more complicated internally to get the desired results. No pun intended."

However, it was not taken into account--as the operations run the same code as for BINARY!.