[PEAK] dispatch -- more specific

Phillip J. Eby pje at telecommunity.com
Tue Dec 13 15:29:59 EST 2005

At 09:15 PM 12/13/2005 +0100, Simon Belak wrote:
>Phillip J. Eby wrote:
>>You can easily make this so by using a rule like "isinstance(a,int) and 
>>a==3", which will then be more specific than "isinstance(a,int)".
>>That is, to force one condition to more specific than another, you need 
>>only explicitly "and" the less specific condition with the more specific 
>>one.  This forces it to be more specific by construction, even if 
>>RuleDispatch could not otherwise infer the implication.
>This is how I am doing it now, but it feels a bit messy (or probably 
>dispatch as a whole has just spoiled me ;))).
>On a related note, can specialisation of a generic function be a generic 
>function. For instance:
>def bar(my_arg):
>    ...
>If so, how do I access it's methods (when() and company)?

In the above example (assuming you meant '@dispatch.on("my_arg")'), you 
would use:

    def whatever(my_arg):

That is, as long as you define the first method using a name different than 
that of the outer generic function, then you can simply refer to it directly.

I'm not sure what usefulness you see in this idea, though, other than that 
it allows you to omit the common condition for individual methods.

More information about the PEAK mailing list