[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: boolean operators
- From: Rici Lake <lua@...>
- Date: Wed, 20 Sep 2006 16:06:55 -0500
On 20-Sep-06, at 3:51 PM, Roberto Ierusalimschy wrote:
Actually, I think he was just talking about needing to use 'and',
'not' instead of '&&', '||', and '!' --- Lua *has* boolean operators.
But I think you were talking about logical operators, which stock Lua
Sure. Sorry about the confusion. (I should call them bitwise
I find bitwise operators useful for representing large subsets;
however, a bitset
limited to some k < 64 is not very useful for that, so i generally use
which keeps the bitsets as strings (although it turns out that the
hash algorithm on strings is not very good for typical bitstrings, but
not horrible either, and I haven't come up with a better one.) It's not
always necessary to intern bitsets, but it is often useful.
If the subsets are not large, then it's better to represent them as
interval lists, which can also be condensed into strings.
I doubt whether these applications are general enough to be worth
in core Lua, though.
For the case of flags coming out of C functions, I personally think that
it is better to translate the flagset in and out into a more usable Lua
structure than to try to use bitwise operators in Lua. That's just a
preference, but it leads to more readable Lua programs, even though they
may not execute quite as fast.