-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Proposal: match bits #2016
Comments
This is a bit of a niche scenario to add a language feature for. It there a more generally useful proposal underlying this? |
I know, it's very specific. |
How much of that is currently done in C#? |
I was going to suggest that this could be solved with your active patterns proposal: public static bool BitPatternMatch(this int value. int mask) => (value & mask) == mask;
if (value is BitPatternMatch(0xb_1001)) …
switch (value)
{
case BitPatternMatch(0xb_1001) : … but you have closed that issue saying that it's no longer required with recursive patterns. How would you solve this with active patterns as I'm confused by your closing comment on that issue? |
In a recursive pattern like that, when the type lookup for Each argument can be a:
This is mostly the same as how we handle |
That's not what I was saying. This is still a separate feature, but the proposed parsing style is out of the question. |
@alrz, ah that makes sense. Thanks. |
should be
First mask tells what bits I want. 2nd mask is to test bits (either set or cleared, can be combined: 1??1, 0??0, 1??0, 0??1). Can I do this with recursive patterns? |
Thanks I will check that |
I'd like to discuss following idea
I'm creating disassemblers and it needs machine instruction decoding. i.e. matching many bit patterns and extracting bits.
Expression to test bits is
For example, to test bits 0 and 3 are set
Using pattern matching could be
where
?
are ignored and can represent any digitor
Some problems I can see:
The text was updated successfully, but these errors were encountered: