Question

I am trying to define a greater than rule in CLIPS but it doesn't seem to be working. Any idea on how I can fix it. The problem seems to be occurring at defrule btwn100and120.

(defrule part-credits
    (or (current-part "a")
        (current-part "b")
        (current-part "c"))
    =>
    (bind ?reply (get-text-from-user "How many points did you achieve?"))
    (assert (part-credits ?reply))
)

(defrule btwn100and120
    (part-credits => 100)
    (part-credits <= 120)
    =>
    (bind ?reply (get-text-from-user "Did you Part A before the changes? (y/n)"))
    (assert (btwn100and120 ?reply))
)
Was it helpful?

Solution

Use the test function to make numerical comparisons. Also, note that CLIPS uses prefix notation for mathematical operators. Here is a simplified rule that does what you want:

(defrule MAIN::btwn100and120
  (part-credits ?val)
  (test (<= ?val 120))
  (test (>= ?val 100))
=>
  (printout t "Value " ?val " is in range." crlf)
)

And here is a test of the rule:

CLIPS> (watch facts)
CLIPS> (watch activations)
CLIPS> (assert (part-credits 99))
==> f-0     (part-credits 99)
<Fact-0>
CLIPS> (assert (part-credits 110))
==> f-1     (part-credits 110)
==> Activation 0      btwn100and120: f-1
<Fact-1>
CLIPS> (run)
Value 110 is in range.
CLIPS> 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top