Hi,

 

I want to delete a list of facts from the working memory and therefore created following rule:

 

rule "delete rule"

  agenda-group "evaluation"

  salience 50

  no-loop true

 

  when

    $facts : ArrayList(size > 0) from collect (Fact())

  then

    logger.info("delete rule, number of facts in list: " + $facts.size());

      

    for (int i = 0; i < $facts.size(); i++) {

       Fact f = (Fact)$facts.get(i);

       logger.info("retract fact id: " + f.getId());

       retract(f);

    }

end

 

When inserting 10 facts with IDs 1 to 10 and then fire all rules, I get following result:

delete rule, number of facts in list: 10

retract fact id: 1

retract fact id: 3

retract fact id: 5

retract fact id: 7

retract fact id: 9

 

but, the facts 2, 4, 6, 8 and 10 are not deleted. I would have expected to set “no-loop” to true, as I do some modification of facts and don’t want that this rule is fired again with the same facts. When I set “no-loop” to false, I get following result:

delete rule, number of facts in list: 10

retract fact id: 1

retract fact id: 3

retract fact id: 5

retract fact id: 7

retract fact id: 9

delete rule, number of facts in list: 5

retract fact id: 2

retract fact id: 6

retract fact id: 10

delete rule, number of facts in list: 2

retract fact id: 4

delete rule, number of facts in list: 1

retract fact id: 8

 

now, all facts are deleted but the “delete rule” was fired 4 times. Is this the intended behavior of Drools? Is there a way to fire a rule only once and delete a list of facts?

I can reproduce this behavior with Drools 5.5.0.Final and 6.0.0.Beta2 but did not try any other version.

 

Best Regards,

Wolfgang