OT(Slightly): Thanks to Python.

Ville Vainio ville at spammers.com
Sat Mar 13 04:08:01 EST 2004


>>>>> "Josiah" == Josiah Carlson <jcarlson at nospam.uci.edu> writes:

    Josiah> Certainly the above can be streamlined with a wrapper function:

    Josiah> def foo1_2(a,b):
    Josiah> print "type 1 & 2"

    Josiah> def foo3_4(a,b):
    Josiah> print "type 3 & 4"

    Josiah> def foo(a,b):
    Josiah> dct = {(type1, type2):foo1_2,
    Josiah> (type3, type4):foo3_4}
    Josiah> return dct[type(a), type(b)](a,b)

Or in Python 2.4 (strict_type is hypothetical for now):

def foo(a,b) [typecheck(type1, type2):
        pass

def foo(a,b) [typecheck(type3, type4):
        pass

which is even nicer :-).



-- 
Ville Vainio   http://tinyurl.com/2prnb



More information about the Python-list mailing list