0
votes

Unsure why this isn't working.

(defrule contain-red?
(initial-fact)
=>
(bind ?reply (get-text-from-user "Does it contain x    (y/n?"))
(assert (existing-text ?reply )))

(defrule partOne
(existing-text "y")
 =>
(bind ?reply (get-text-from-user "give me a number"))
(assert (credit-value-bsc-first-result (explode$ ?reply ))))

(defrule partTwo
(existing-text "n")
=>
(bind ?reply (get-text-from-user "give me a number"))
(assert (credit-value-bsc-second-result (explode$ ?reply ))))

(defrule learn-about-120?
(credit-value-bsc-first-result ?n)
(credit-value-bsc-second-result ?x)
(test (or (<= ?n  20) (<= ?x 20)))
=>
(bind ?reply (get-text-from-user  "Reponse here)"))
(assert (learn-about-120-response ?reply )))

I can get the final rule to work using an and in a different scenario. When loading this into wxCLIPS no errors appear, but when I run it and enter the relevant data the final rule doesn't fire.

1
It is not necessary to add the initial-fact to a rule with no other conditions; it is added automatically in versions of CLIPS prior to version 6.3. The initial-fact functionality was deprecated in the 6.3 release; it is still asserted by a reset, but rules without conditions no longer rely on it. In the 6.4 release, the initial-fact is no longer asserted, so rules that explicitly match this fact will no longer be activated. - Gary Riley

1 Answers

0
votes

The fact credit-value-bc-first-result is only created if existing-text is "y". The fact credit-value-bc-second-result is only created if existing-text is "n". If only one existing-text fact exists, then these conditions are mutually exclusive. Since rule learn-about-120? requires both of these facts it will not fire.

Writing the rule this way is probably what you want:

(defrule learn-about-120?
   (or (credit-value-bsc-first-result ?n)
       (credit-value-bsc-second-result ?n))
   (test (<= ?n  20))
   =>
   (bind ?reply (get-text-from-user  "Reponse here)"))
   (assert (learn-about-120-response ?reply )))