-
Notifications
You must be signed in to change notification settings - Fork 114
Open
Labels
Description
clara.test-rules> (defrule demo-rule [First] [?s <- Second] => (retract! ?s))
#'clara.test-rules/demo-rule
clara.test-rules> (defquery get-second [] [?s <- Second])
#'clara.test-rules/get-second
clara.test-rules> (def empty-session (mk-session [demo-rule get-second] :cache false))
#'clara.test-rules/empty-session
clara.test-rules> (-> empty-session (insert (->First) (->Second) (->Second)) fire-rules (query get-second))
({:?s {}})
I would expect to not get any Second facts from the query after firing the rules in this session, but instead I get 1 Second fact. I believe this is related to the behavior Jerry Jackson reported on the mailing list:
Also, I don't understand how this rule:
(defrule one-service
""
{:salience 2000}
[?svc1 <- :service [{id :id}] (= ?id1 id)]
[?svc2 <- :service [{id :id}] (= ?id2 id)]
[:test (= ?id1 ?id2)]
=>
(retract! ?svc2))
can result in more than one service with the same id remaining in working memory. Why doesn't it continue to fire until there is only one left?
Again, thanks for any help.
I created a more simplified example that eliminates the behavior of facts joining with themselves. In this example, I believe what happens is as follows, with inline links to relevant places in the code.
- Two activations of the rule are queued.
- The first activation is selected from the stack.
- The RHS of the rule is fired once and a RHS retraction of a Second is placed in a buffer.
- The RHS retraction is flushed after the rule activation completes and immediately propagated into the Rete network.
- When this retraction reaches the ProductionNode it causes the second pending activation to be removed.
As a result, demo-rule only fires once and only one Second fact is retracted.
Reactions are currently unavailable