I want to rematch the rule when using CLIPS. But the refresh command doesn't work well every time. So I did some test but still confused about it.
Q1: can (refresh) work with those rules modifing facts? I create a .CLP:
> (defglobal ?*lock* = 0)
>
> (deftemplate counter
> (slot number))
>
> (deffacts initial-data
> (counter (number 0)))
>
> (defrule rule-1
> ?f<-(counter (number ?x))
> (test (= ?*lock* 0))
> =>
> (printout t "counter number1" crlf)
> (bind ?*lock* (+ ?*lock* 10))
> (modify ?f (number (+ ?x 1)))
> )
>
> (defrule rule-2
> ?f<-(counter (number ?x))
> (test (= ?*lock* 10))
> =>
> (printout t "counter number2" crlf)
> (bind ?*lock* 0)
> )
after run the first time, the lock becomes to 0. but then I type (refresh rule-1), the rule-1 doesn't enter into the agenda. I wonder if it is because the modify action in the RHS cause the problem.
Q2: does the global value work in the LHS when using refresh?
another strange point is that after run for the first time. the lock has been changed to 0.I type (refresh rule-2), and find rule-2 is in the agenda again. But the LHS of rule-2 has restrict that lock should equals to 10 if rule to want to be matched. It seems that the test condition doesn't work at all. But the test condition has actually works when I first run the system which I mean typing (reset) and (run) to run the system. what show on the terminal is like this:
CLIPS> (reset) ==> Activation 0 rule-1: f-1 CLIPS> (facts) f-0 (initial-fact) f-1 (counter (number 0)) For a total of 2 facts. CLIPS> (run) counter number1 ==> Activation 0 rule-2: f-2 counter number2 CLIPS> (refresh rule-1) CLIPS> (refresh rule-2) ==> Activation 0 rule-2: f-2 CLIPS> (run) counter number2
I wonder if there is some different between (run) and (refresh) when firing rules?
It really confuses me. Thank you for any answer.