Fork me on GitHub

I have a question about using guards on rules in Clara. I am aiming to create rules that can never insert a fact that already exist. The guard statement works fine if I am manually inserting the fact that the guard stops, but if the rule itself is creating this statement the guard does not stop the rule from triggering again and I get an infinite loop.


ya thats a tricky one ive dealt with too. i'm not sure what the solution is either.


with a naive implementation of rules where each rule is checked separately I can see this not being an issue as after each insertion the guard would be checked and with the new fact that guard would be passed. Could this be a bug in the implementation, where somehow not the full condition of the rule is checked for it to fire again?


maybe i didnt understand what you meant by gaurds, but if a rule inserts something that that same rule looks at, its pretty much always going to cause another firing


is my understanding


I think i figured out the roof of the problem


I compeltely glanced over the fact that clara does truth maintenance


this means if the result of the rule puts in the guard of the rule the fact loses support gets retracted and the rule fires again


I feel very dense about this


You can use unconditional insertions that wonโ€™t use truth maintenance if necessary. In our use cases we strongly prefer truth maintenance and find that it makes the code simpler to reason about, but obviously use-cases differ


i was staring at this like a whole evening thinking what the problem could be, whoops.


It is a common point of confusion ๐Ÿ™‚


It kind of solves pretty much every problem I had with clara though, so that is a relief


so you are saying you were stuck in an infinite loop about the infinite loop and the truth about truth maintenence resolved it


yeah basically using a guard with truth maintenance, where the result of the rule (or another) triggers the guard can start an infinite loop


especially in the case where it is just a single rule that triggers the guard


(i was just making a light hearted joke about how your proccess of realizing how it was working was similar to a rules network) though your understanding sounds correct to me


well like I said I feel dense today


Overview of the talk @mikerod gave at the Clojure/conj 2016 conference.


Oh yes. Still cleaning up that site some. Going to change the theme since it sucks on mobile. However the content is there.


nope this is permanent now


weve seen everything


@mikerod Okay, I'll resist the urge to tweet about it until you have the finishing touches in place. ๐Ÿ˜„


Haha. Thanks. I'll fix it within a day or so. Out of town so I'm a bit slow.