[MATRIX-SIG] umath.logical_blah vs normal python functions.

Perry A. Stoll pas@xis.xerox.com
Tue, 18 Nov 1997 14:54:35 PST


> Yes, but the boolean_and of 4 and 5 is 4. It is incomprehensible how the
> '4 and 5' construct comes up with 5.

def _and(*args):
	arg = None
	for arg in args:
		if not arg: return None
	return arg
 
>>> _and(4,5)
5

 Incidentally, '4 or 5' comes out 4.

def _or(*args):
	arg = None
	for arg in args:
		if arg: return arg
	return arg
>>> _or(4,5)
4

These are almost what the builtins do, except that the arguments are 
evaluated here for the function call. They aren't evaluated in Python
(or C) until they are tested.

Note also that umath.logical_and() returns only 1 or 0 values, which is
not the same one gets using the normal Python operators.

Add my vote for the name change to bitwise_and...I still don't know
which is supposed to do what: "logical"??? "boolean"???

-Perry





_______________
MATRIX-SIG  - SIG on Matrix Math for Python

send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
_______________