Fwd: RE: [Jython-users] overloading methods From: Glen Starchman - 2001-04-04 18:02:47 ```---------- Forwarded Message ---------- Subject: RE: [Jython-users] overloading methods Date: Wed, 4 Apr 2001 11:44:26 -0700 From: Glen Starchman On Wed, 04 Apr 2001, Brian Zimmer wrote: > > The correct way to do this is: > > def mything(a, b, c=None): > """ do something, like check if 'c' is not None """ > if c: > print a, b, c > else: > print a, b But that begins to get complicated if you need to "overload" with several different types of parameters, doesn't it? I am not a big fan of overloading, but sometimes it is a necessary evil. I found an interesting approach with Lua for overloading (bear in mind, I don't know Lua very well and this is just my interpretation of how it works): function fn_iii(a,b,c) #takes three integers function fn_is(a,b) #takes an integer and a string function fn_ii(a,b) #takes two integers to call the function, just call fn() with the correct number of params and the runtime will analyze the params and call the appropriate function. Obviously the problem comes into play when a param is not a built-in type (eg...some random object). Not an exactly elegant solution, but it appears to work. -- c=(0x47, 0x6c, 0x65, 0x6e, 0x40, 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x76, 0x65, 0x6e, 0x74, 0x75, 0x72, 0x65, 0x73, 0x2e, 0x63, 0x6f, 0x6d) for z in map(eval("lambda _y:_y "), range(len(c))):print repr((map( lambda q:chr(c[z]),c))).join( chr(c[z])).lower(), ------------------------------------------------------- -- c=(0x47, 0x6c, 0x65, 0x6e, 0x40, 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x76, 0x65, 0x6e, 0x74, 0x75, 0x72, 0x65, 0x73, 0x2e, 0x63, 0x6f, 0x6d) for z in map(eval("lambda _y:-_y "), range(len(c))):print repr((map( lambda q:chr(c[z]),c))).join( chr(c[z])).lower(), ```

 Fwd: RE: [Jython-users] overloading methods From: Glen Starchman - 2001-04-04 18:02:47 ```---------- Forwarded Message ---------- Subject: RE: [Jython-users] overloading methods Date: Wed, 4 Apr 2001 11:44:26 -0700 From: Glen Starchman On Wed, 04 Apr 2001, Brian Zimmer wrote: > > The correct way to do this is: > > def mything(a, b, c=None): > """ do something, like check if 'c' is not None """ > if c: > print a, b, c > else: > print a, b But that begins to get complicated if you need to "overload" with several different types of parameters, doesn't it? I am not a big fan of overloading, but sometimes it is a necessary evil. I found an interesting approach with Lua for overloading (bear in mind, I don't know Lua very well and this is just my interpretation of how it works): function fn_iii(a,b,c) #takes three integers function fn_is(a,b) #takes an integer and a string function fn_ii(a,b) #takes two integers to call the function, just call fn() with the correct number of params and the runtime will analyze the params and call the appropriate function. Obviously the problem comes into play when a param is not a built-in type (eg...some random object). Not an exactly elegant solution, but it appears to work. -- c=(0x47, 0x6c, 0x65, 0x6e, 0x40, 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x76, 0x65, 0x6e, 0x74, 0x75, 0x72, 0x65, 0x73, 0x2e, 0x63, 0x6f, 0x6d) for z in map(eval("lambda _y:_y "), range(len(c))):print repr((map( lambda q:chr(c[z]),c))).join( chr(c[z])).lower(), ------------------------------------------------------- -- c=(0x47, 0x6c, 0x65, 0x6e, 0x40, 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x76, 0x65, 0x6e, 0x74, 0x75, 0x72, 0x65, 0x73, 0x2e, 0x63, 0x6f, 0x6d) for z in map(eval("lambda _y:-_y "), range(len(c))):print repr((map( lambda q:chr(c[z]),c))).join( chr(c[z])).lower(), ```