jruizgit / rules

Durable Rules Engine
MIT License
1.14k stars 207 forks source link

Not working or #308

Open Kampfzwerg42 opened 4 years ago

Kampfzwerg42 commented 4 years ago

The or(|) seems not working correctly at complex Rules. In the small example below nothing is returned isntead of '2 counter match' as I expect. Also if I change 'secondCount' also to 1 '2 counter match' is returned twice instead of once as I would expect in such a situation. from durable.lang import * with ruleset('expense'): @when_all(c.first<<(+m.counter), c.second<<((m.countersValid==True) & ((m.primeCount == c.first.counter) | (m.secondCount == c.first.counter)) ) ) def match(c): print ('2 counter match') assert_fact('expense', { 'counter': 1}) assert_fact('expense', { 'primeCount': 1,'secondCount':3,'countersValid':True})

jruizgit commented 4 years ago

Hi, thanks for reporting this issue. I have pushed the first part of the fix for the problem. I still need to handle duplicate expression frames. It will take me a few more days to complete the fix.

jruizgit commented 4 years ago

Hi, I have published a fix for this issue. Please use version 2.0.20. Your example should now work as expected.

Kampfzwerg42 commented 3 years ago

There are still problems with the or(following code produces no output uncomment the last line produces 2x Reaction as output):



with ruleset("Test"):
    @when_all(
        c.F << +m.a
        ,   (m.a == c.F.a) |
            (+m.a)
    )
    def reaction(c):
        print("Reaction")

assert_fact("Test", {'a': 10})
assert_fact("Test", {'a': 20})
#assert_fact("Test", {'a': 20, 'b': 3})