metaeducation / rebol-issues

6 stars 1 forks source link

COMPLEMENT bitset limitations #1085

Open rebolbot opened 15 years ago

rebolbot commented 15 years ago

Submitted by: Ladislav

It is known that complement bitset does not work as it did in R2. The question is, whether there should be some warning/error/additional documentation.

A possible solution: since the COMPLEMENT result for bitsets is usually not what it is expected to be, an alternative may be to not support complement for bitsets (cause error) and tell user to convert the bitset to binary, pad by zeros as needed, complement and convert back.

An option is to introduce a special PAD function padding a bitset with #{00}s or #{FF}s

>> a-bitset: charset " "
== make bitset! #{0000000080}

>> a-binary: to binary! a-bitset
== #{0000000080}

>> append/dup a-binary #{00} 32 - length? a-binary
== #{0000000080000000000000000000000000000000000000000000000000000000}

>> to bitset! complement a-binary
== make bitset! #{FFFFFFFF7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF}

CC - Data [ Version: alpha 70 Type: Issue Platform: All Category: Datatype Reproduce: Always Fixed-in:none ]

rebolbot commented 15 years ago

Submitted by: BrianH

Don't make a function called PAD with a purpose so specific - the name is too valuable to waste like that. Sounds like a good function to have though.

Bitsets seem to use three-valued logic when you consider complementing, length and equality. There is a workaround that almost works, since INSERT or APPEND bitset! block! use the same syntax as MAKE bitset! block!. This lets you do things like this:

>> insert make bitset! 256 [#"0" - #"9"]
== make bitset! #{
000000000000FFC0000000000000000000000000000000000000000000000000
00
}

However, there's a problem with the length of the generated bitset!:

>> length? make bitset! 256
== 264

I'll make a bug ticket for that and a request for a /length refinement to CHARSET. Once those are implemented and the documentation for bitset! is written we can mark this ticket as resolved.

rebolbot commented 15 years ago

Submitted by: Carl

Another method would be to use a virtual complement. This would be implemented with a flag on the bitset to make it act complemented. Bits out of range would also be complemented.

This change would allow complemented bitsets to be used with PARSE again.

rebolbot commented 15 years ago

Submitted by: BrianH

As long as there is a MAKE bitset! spec and a serialized syntax for the complemented attribute, why not? That would make #1091 and #1092 less necessary.

rebolbot commented 15 years ago

Submitted by: Carl

A91 provides complemented bitsets (using a flag to indicate the complement.)

Most R2 apps that use complemented bitsets in simple ways (e.g. with PARSE or FIND) will work as-is without modifications. Those that MOLD complemented bitsets and process or modify the resulting string will need to be updated.