See below.
On 09/06/2012, bdolbeare <bdolbeare(a)yahoo.com> wrote:
Thank you for your response.
The main part of my question is why doesn't the second rule produce the
same
results -- I was expecting two matches but it only produces one. The only
thing I can think of is that it's an order of operations issue but that
doesn't seem to make sense given the parenthesis. The second pattern in
that rule is basically:
condition || (! condition && unification)
This should produce two matches with the given data but, it doesn't produce
a match when the condition left of the || is satisfied (in that case the
unification shouldn't be happening but, maybe it is?). If I change the
rule
to the following, it does produce two matches which makes me believe that
the unification is affecting things.
So, actually the question is: what is to be expected from
f1 : Foo ( item != null, $item := item )
and another pattern that is one of:
f2 : Foo ( item == null || item != null && $item := item ) # (a)
f2 : Foo ( item == null || $item := item ) # (b)
f2 : Foo ( item == null || item != null
) # (c)
For (a) and (b), there must be instances of Foo where one particular
item object satisfies the (remaining) constraints, whereas (c) will
fire for any Foo, since item == null || item != null reduces to true.
Unification on some Foo's item (where item != null) restricts
potential firings where the Foo instances bound to f1 and f2 point to
the same Item (which must not be null). Thus, in (a) we have one Foo
object that can be instantiated with a unified Item object. In (b),
the constraint demands an item == null, and certainly there's no way
to satisfy both, item != null and item == null.
(a) fires once, (b) doesn't fire at all, (c) fires twice.
There is, however, on open question, i.e., why a binding that is not
in the context of a Boolean expression can be written as an operand to
|| or &&. Clearly, $item := item isn't a Boolean expression, and
therefore an expression such as a > b && $item := item (item not a
Boolean) is nonsense, whereas a > b && $item := item != null is
acceptable as a shorthand.
-W