[PEAK] dispatch -- more specific
Phillip J. Eby
pje at telecommunity.com
Tue Dec 13 15:08:29 EST 2005
At 08:54 PM 12/13/2005 +0100, Simon Belak wrote:
>Hi,
>
>is "more specific" just a measure of the number of logical expressions in
>a case or is there more to it than that?
It is logical implication. If there are two conditions X and Y, then X is
more specific than Y if:
1. whenever X is true, Y is true by definition
2. when Y is true, X may or may not be true
For RuleDispatch to detect these conditions in practice, it must use each
subexpression condition, and it does not handle any crossover implication
between types of conditions. That is, it can know that a==3 implies a<=4
and a>2, but it does not know that a==3 implies isinstance(a,int). In
fact, Python's equality rules don't imply that, either, since a might be
the float 3.0 or the long 3L.
>What I would like is a strategy where equals (==) is more specific than
>other relations (e.g. isinstacnte).
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.
More information about the PEAK
mailing list