Hello,
I want have a record to assert that two things are equivalent:
(defrecord Eq [obj1 obj2])
I also want to have a rule that says "If (Eq X Y), then (Eq Y X)". My first pass at the rule looks like this:
(defrule eq-symmetry
""
[Eq (= ?x x) (= ?y y)]
=>
(insert! (->Eq ?y ?x)))
As I came to understand, this causes an infinite loop because the RHS generate a new fact that matches the LHS condition, which generate another fact. Since there can be multiple facts that are equal (but not identical), this goes on forever.
I have also tried using accumulator and/or negation to make sure that I don't add a fact that already exists. The problem with that, as I understand, is when the LHS matches, I insert a new Eq fact, which invalidates the LHS, causing that insertion to be retracted, causing LHS to match again. I can't seem to come up with a way to keep facts "unique"
This is actually a boiled down version of a more messy problem I'm dealing with, and I think I'm missing some fundamental understanding. Here are some questions, all related to each other:
1.) How would you get around this problem I have?
2.) Am I using the rule engine the way it should be used? Am I modeling my problem correctly?
3.) In general, how do you avoid the looping situation caused by (a.) LHS and RHS keep matching each other and (b.) RHS invalidates LHS? Related to that, is there a way to say "Add fact X if it hasn't been stated before"?
Thank you very much