[rules-users] Pattern order affects activation

Wolfgang Laun wolfgang.laun at gmail.com
Thu Feb 14 13:14:20 EST 2013


FWIW, the corrected rule works, irrespective of the position of the "exists" CE.

rule killphone
when
    exists Customer()
    $unused: Phone( $value: value )
    not Customer( phone == $value )
then
    retract( $unused );
end

-W


On 14/02/2013, Wolfgang Laun <wolfgang.laun at gmail.com> wrote:
> Please restate your problem, correcting (see below)...
>
> On 14/02/2013, DOLECEK Ales <Ales.Dolecek at nextiraone.eu> wrote:
>
>> rule "Remove unsued phones"
>> 	when
>> 		exists Customer()
>> 		not Customer(phone == $value)
>> 		$unused: Phone($value: value)
>> 	then
>> 		retract($unused);
>> end
>
> Provide the accurate code of your rule. This one isn't correct, since
> use of $value precedes its definition....
>
>
>>
>> There might be multiple Customer and Phone facts in the working memory
>> and
>> the purpose of the rule is to remove phones that do not belong to any of
>> the
>> customers. The rule should not be activated while there are no Customers
>> in
>> WM - hence the "exists Customer()". This is becaus there are other rules,
>> taht might use the phones to lookup customers.
>>
>> There Phone with value = "test" in working memory when Customer with phone
>> =
>> "test" is inserted. BTW: Both facts are immutable.
>
> Please provide a more accurate description, preferably (correct &
> working) Java code.
>
> -W
>
>>
>> The behavior differs depending on order of the 3 patterns in the LHS of
>> the
>> rule.
>>
>> 1) If the "exists Customer()" is first activation is created
>> 	- this is wrong since the "exists Customer()" shall be false
>>
>> 2) if I move the "exists Customer()" between the other patterns
>> activation
>> is created and immediatelly canceled
>> 	- this is also wrong since, although in my case (where are no side
>> effects)
>> it works
>>
>> 3) Finally if the "exists Customer()" comes last the then activation is
>> not
>> created at all
>> 	- this is correct
>>
>> Is this bug or am I missing something important about rule language?
>> Rewriting the LHS with expicit infix and does not help:
>>
>> 		(exists Customer()) and
>> 		(not Customer(phone == $value)) and
>> 		($unused: Phone($value: value))
>>
>>
>> Ales
>>
>> FYI: I'm using 5.5.0.Final
>> _______________________________________________
>> rules-users mailing list
>> rules-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>


More information about the rules-users mailing list