| Store | Cart

OT(Slightly): Thanks to Python.

From: Ville Vainio <vil...@spammers.com>
13 Mar 2004 11:08:01 +0200
>>>>> "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

Recent Messages in this Thread
Aahz Mar 10, 2004 10:48 pm
David M. Wilson Mar 10, 2004 08:34 pm
Jacek Generowicz Mar 08, 2004 09:24 am
JanC Mar 09, 2004 09:25 pm
Michael Hudson Mar 10, 2004 11:47 am
Jacek Generowicz Mar 10, 2004 03:03 pm
JanC Mar 13, 2004 05:24 am
Josiah Carlson Mar 13, 2004 07:17 am
Ville Vainio Mar 13, 2004 09:08 am
Ville Vainio Mar 13, 2004 09:17 am
Messages in this thread