0

In Rebol 2 you could check for an empty bitset with EMPTY?

>> empty? make bitset! #{00}
== true

In Rebol 3 (Build 21-Feb-2011/0:44:24) this is not the case.

>> empty? make bitset! #{00}
== false

Bug or new behavior? Either way, how else might I do this test? Empty bitsets of different sizes do not compare as equal in either R2 or R3:

>> (make bitset! #{00}) == (make bitset! #{0000})
== false

2 Answers2

1

New behaviour: a bitset with >0 bits is not empty; even if it has no bits set, it still contains cleared bits.

In R3, you can or a given bitset with the empty bitset, to find out if the first is empty -- that is: it has no bits set -- as well:

>> empty? (make bitset! #{00}) or (make bitset! #{})
== true

>> empty? (make bitset! #{0000}) or (make bitset! #{})
== true

As a convenient shortcut, you can also just or with an empty binary!, enabling the following definition:

bitset-clear?: func [bitset [bitset!]] [empty? bitset or #{}]

Again, using your examples:

>> bitset-clear? make bitset! #{00}   
== true

>> bitset-clear? make bitset! #{0000}
== true
earl
  • 40,327
  • 6
  • 58
  • 59
  • Gotcha. I figured it was a bit too elementary to be a bug, but I still don't entirely grok the rationale for the change. The fix works, and [Cyphre offered the same thing](http://chat.stackoverflow.com/transcript/message/6293069#6293069). *(Note again the chat linking. Can we please get more Rebol people to realize the value of StackExchange? Help me out, here.)* It feels like a bit of a tenuous contract to depend on this invariant property of OR, but if it's a rule then it's a rule... :-/ – HostileFork says dont trust SE Nov 20 '12 at 12:57
  • The rationale might stem from a "series interpretation" of bitsets (I added a sentence towards that motivation). But then, a bitset! is not a member of the series! typeset. – earl Nov 20 '12 at 13:01
  • I concur with @HostileFork, this is incredibly odd behavior. I had to re-read this entry several times to understand what was happening with `or` and an empty bitset. This seems excessively complex compared to the very simple and understandable behavior of EMPTY? in R2... – DocKimbel Dec 19 '13 at 15:08
0

Could be one of the differences in the way bitsets are constructed between R2 and R3. This still holds in R3 (A111):

>> eb: charset []
== make bitset! #{}

>> empty? eb
== true
rgchris
  • 3,698
  • 19
  • 19