[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: Bitflags
- From: John Mckenna <jmckenna@...>
- Date: Wed, 5 Mar 2003 09:56:53 -0000
Alex Bilyk writes:
>> 'flags = FOO_BLUEPANTS + FOO_3PLANES + FOO_EDIBLE' ?
>This will result in totally unreadable/misinterpreted code, IMHO. The
>assumption that '+' can somehow intuitively be realted to '|' is ungrounded
>to say the least.
On the "all programming languages look like C" planet, perhaps. For the
rest of us, the use of | for a set union operator is totally baffling.
My first choice would be the standard mathematical symbols. But that
requires Unicode - maybe the industry will have got its act together in ten
years or so. I want to be able to type these things easily.
My second choice: + for union, - for difference (A - B is the members of A
that are not members of B), and * for intersection. The empty set is nil.
Then you can say
FOO_ALL = FOO_BLUEPANTS + FOO_3PLANES + FOO_EDIBLE + FOO_WOBBLY + FOO_ALIEN
if flags * (FOO_ALL - FOO_EDIBLE) then
end
I believe this can be implemented in pure Lua, or with C helper functions
for speed. Certainly no changes to the core language are required.
-Virus scanned and cleared ok