Exotic Logics

Steven D'Aprano steven at REMOVE.THIS.cybersource.com.au
Wed Jun 17 04:44:19 EDT 2009

On Tue, 16 Jun 2009 22:46:14 -0700, William Clifford wrote:

> I was staring at a logic table the other day, and I asked myself, "what
> if one wanted to play with exotic logics; how might one do it?"

This might be useful for you, and if not useful, at least it might blow 
your mind like it did mine.

(This is not original to me -- I didn't create it. However, I can't find 
the original source.)

Imagine for a moment that there are no boolean values. 
There are no numbers.  They were never invented.
There are no classes.
There are no objects.
There are only functions.

Could you define functions that act like boolean values? And could you 
define other functions to operate on them?

def true(x, y):
    return x

def false(x, y):
    return y

def print_bool(b):
    print b("true", "false")


def Not(b):
    def not_b(x, y):
        return b(y, x)
    return not_b


def And(a, b):
    return a(b, a)

def Or(a, b):
    return a(a, b)

print_bool(And(true, true))
print_bool(And(true, false))
print_bool(Or(false, true))
print_bool(Or(false, false))


More information about the Python-list mailing list