Newbie: Truth values (three-valued logic)

David Ascher da at ski.org
Tue Jun 15 22:47:11 CEST 1999


On Tue, 15 Jun 1999, Olaf Delgado wrote:

> This behaviour is completely consistent in a two-valued logic, but not
> what I actually want, because maybe should neither be true nor false, nor
> should its negation. As far as I know, the logical negation operator can
> not be overloaded, so I have no chance to change this, right? No big deal,
> really, but I'd like to know if I missed something here. So, is there some
> magical trickery to achieve the behaviour I want?

I don't believe so, due to the following bit in ceval.c:cmp_outcome:

	case IS:
	case IS_NOT:
		res = (v == w);
		if (op == (int) IS_NOT)
			res = !res;
		break;


In other words, the behavior of 'not' is based on the operation of C's !
operator on an int.  

Of course, it could be changed (e.g. by adding a __not__ special hook),
but the added code complexity and speed hit would have to be justified.

Actually, after looking at the documentation for the operator module, I
think that there's a documentation problem -- reading it, one would think
that there is a __not__ special method, but it is not supported by the
core.  I think a special comment should be added to the doc to that
effect.

--david ascher






More information about the Python-list mailing list