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

Tutorial "Enum" contains a mistake #72

Open
MidimasterSoft opened this issue Jan 25, 2022 · 5 comments
Open

Tutorial "Enum" contains a mistake #72

MidimasterSoft opened this issue Jan 25, 2022 · 5 comments

Comments

@MidimasterSoft
Copy link

I read the chapter about ENUMs at your homepage:
https://blitzmax.org/docs/en/language/enums/
and found this:
ScreenshotEnumBug

Here you write that a XOR-operation removes a flag from the variable meetingDays. But this is only correct if the flag is already part of the variable. In cases, where the flag is not there this would cause a complete wrong result.The flag will be added:

SuperStrict 
Enum EDays flags
    Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
End Enum

Local meetingDays:EDays = EDays.Tuesday | EDays.Thursday


' Remove a flag using bitwise XOr.
meetingDays :~ EDays.Saturday

Print "Meeting days are " + meetingDays.ToString()

The better operation is a combination of AND and XOR. This 100% removes a BIT from a variable:

SuperStrict 
Enum EDays flags
    Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
End Enum

Local meetingDays:EDays = EDays.Tuesday | EDays.Thursday


' Remove a flag using bitwise XOr.
meetingDays :&~ EDays.Saturday    '   <--------  SEE CHANGE HERE

Print "Meeting days are " + meetingDays.ToString()
@woollybah
Copy link
Member

I believe the documentation is correct, because that is how XOR works.
If a flag it set, it will unset it. If a flag is unset, it will set it.

The example describes using XOR to remove an enum from a set.

@GWRon
Copy link
Contributor

GWRon commented Jan 27, 2022

Then it should possibly inform that "xor" is not simply "unsetting" ... it can have "side effects" (for not yet set flags).

It acts as a "switch/flip" there. So maybe add an example (line in the sample) on how to remove something which "might" be set.

@MidimasterSoft
Copy link
Author

Then it should possibly inform that "xor" is not simply "unsetting" ... <

But that's what is written in the Tutorial:
"Remove a flag using XOR"

..means for me "For removing a flag use XOR" And this is wrong. XOR swaps the state, but does not remove.

A clear "Removing" can only be done with the combination of AND and XOR. So why not writing:


Remove a flag using bitwise AND and XOr.
meetingDays :&~ EDays.Saturday

I'm only reporting... you decide. Thats ok for me.

@GWRon
Copy link
Contributor

GWRon commented Jan 27, 2022

meetingDays :&~ EDays.Saturday

you should write this as: meetingDays :& ~EDays.Saturday as this is what you then do: you want to know what "meetingDays AND (complete enum except saturday)" have in common.
(~EDays.Saturday is "Monday|Tuesday|Wednesday|Thursday|Friday|Saturday")

@MidimasterSoft
Copy link
Author

... (~EDays.Saturday is "Monday|Tuesday|Wednesday|Thursday|Friday|Saturday")

typo:
~EDays.Saturday is "Monday|Tuesday|Wednesday|Thursday|Friday|Sunday"

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

3 participants