With the creation of ENBIN and DEBIN, I think I showed off how a Rebol approach of dialecting could truly make something easy that's painful in other languages (and a historical pain point in Rebol too, with how people had to wrestle with TO INTEGER! and TO BINARY! conversions).
Under the buzzword BITWISE I've had the notion that a little dialect specifically tailored to bit shifting and masking could be created. While I don't have a clue what it would look like, one thought I had was that instead of trying to come up with a name for AND and OR that's bitwise like AND+ or OR+ (or BITAND and BITOR), instead you'd be able to say something like bitwise [x and y].
But the idea is that bitwise would be so capable, that instead of grumbling about how it sucked that you had to type it in, that you would fall into a universe of fast binary functionality that would more likely than not be where you wanted to be if you were in the mode of writing bitwise math.
I know more about what I'd want this dialect to do (and do efficiently) than I know about what it would look like. Here's a list of "Magic" C snippets for doing binary operations. What bag of tricks might bitwise bring?
Should be able to do:
- Shifting and Rotation (shift with carry of high bits around to low or vice-versa)
- Clipping (constrain to 31 bits came up today)
- Most/least significant 1 bit or 0 bit (Nth most/least?)
I don't know that I'd rule out being able to do PARSE-like things at a bit level, maybe being able to scan bits from low to high and flip or operate on them as you went...injecting plain code to run as you go (also as PARSE allows?)
But it needs to be easy to escape out of. I don't know if that means that BLOCK! is used for grouping and then parentheses become plain code, or what.
I personally think bitwise [x and y] looks favorable compared with x and+ y, so I'll just start the conversation there. Anyone want to offer up some scenarios of how it might throw in power tools for the bit fiddler?
Might it always evaluate to a result which you can say how many bits you want, e.g.
bitwise/bits [x and y] 31
Make it a skippable parameter as well, to give you the alternative:
bitwise 31 [x and y]
Stuff like that. It likely would need to incorporate some of ENBIN and DEBIN's smarts to be useful.
What kind of controls might it have for overflow? Could it be done in a way that lets you do custom overflow handling if it returns NULL, but then has another value it sets which is the overflow out of the range you specified?