Skip to content

ProductionNode removes a pending activation when a retraction corresponds to a previously-fired activation from an equal token #321

@WilliamParker

Description

@WilliamParker
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.

As a result, demo-rule only fires once and only one Second fact is retracted.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions