Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bit pattern matching #374

Open
mneumann opened this issue Sep 11, 2022 · 1 comment
Open

Bit pattern matching #374

mneumann opened this issue Sep 11, 2022 · 1 comment

Comments

@mneumann
Copy link
Contributor

Just looking at msgpack spec, which defines a table like this to decode the type of the following value:

positive fixint | 0xxxxxxx
fixmap          | 1000xxxx
...
nil             | 11000000

The code to test for example for "positive fixint" looks like

first_byte.bit_and(0b10000000).is_nonzero

which IMHO is un-intuitive.

It would be nice to write something along the lines:

first_byte =~ b/0xxxxxxx/

This would require a new BitMask type and a new literal to create it. Once we have custom string literals (#247), we could create e.g. a BitMask using something like '0xxxxxxx'_bitmask. This would actually be simple if we had some kind of comptime evaluations, then we could just add a method bitmask! on String.

@mneumann
Copy link
Contributor Author

Or something like Ocaml's Bitstring: https://ocaml.org/p/bitstring/latest/doc/Bitstring/index.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant