• Subject: Re: tribool
• Date: Wed, 17 Nov 2010 16:56:09 +0300

```On Wed, Nov 17, 2010 at 14:56, Leo Razoumov <slonik.az@gmail.com> wrote:
> On Wed, Nov 17, 2010 at 01:31, Alexander Gladysh <agladysh@gmail.com> wrote:
>> On Wed, Nov 17, 2010 at 08:13, Doug Currie <doug.currie@gmail.com> wrote:
>>> On Nov 16, 2010, at 11:51 PM, Alexander Gladysh wrote:

>>>> I'm looking for the Lua equivalent for this:

>>>> http://www.boost.org/doc/libs/1_44_0/doc/html/tribool.html

>>> You can get a long way with using

>>> true := 1.0
>>> false := 0.0
>>> indeterminate := NaN

>> Nice!

>> But NaN is not a first-class-citizen in Lua.

>> I think that sooner or later I'll want to do t[indeterminate] = value.

> How about the balanced ternary system:

> tri_true= -1
> tri_unknown= 0
> tri_false= 1

> function tri_and(x,y) return max(x,y) end
> function tri_or(x,y) return min(x,y) end
> function tri_not(x,y) return -x end
> function tri_xor(x,y) return x*y end

Looks good, thanks!

Now I need to separate that from the actual numbers.

That is, to make a new "Lua type" so, at least, I can check that
function returned indeterminate, not proper 0. I'm aware that Lua
lacks virtualization in some places, so I will not be able to make
tribool looking like bool to user.

But that's OK, I will generate most of the code that works with it
automatically anyway. That is, I can afford to use some method calls
instead of using standard Lua operators to work with tribools.

Any suggestions on the module interface?

Thanks,
Alexander.

```