[PEAK] Allowing ambiguity in generic functions?

Phillip J. Eby pje at telecommunity.com
Sat Jan 1 03:01:45 EST 2005


At 05:53 PM 12/31/04 -0500, Andy Gross wrote:

>I'm sure it's possible, maybe with something along the lines of 
>dispatch.strategy.chained_methods?
>
>I'll be taking user-inputted expressions and using those as rules for a 
>generic function.  In the case where
>more than one rule matches, I'd like to get a list of the results of all 
>matching functions.
>
>Any advice?

Just make your own combiner, and use that as the argument to dispatch.generic:

def my_combiner(funcs):
     def combined(*__args,*__kw):
         # Call each of the applicable methods
         return [f(*__args,*__kw) for f in funcs]
     return combined

@dispatch.generic(my_combiner)
def gfunc_that_returns_list_of_results(...):
     ...


Note, by the way, that I may be changing the API for method combiners soon, 
so it can receive the actual generic function or dispatcher as well as the 
combining methods.  So, if I do that, the 'my_combiner' signature would 
need to change.




More information about the PEAK mailing list