2012-11-25 123 views
2

我想在CLIPS中定義一個大於規則,但似乎沒有工作。任何想法如何我可以解決它。這個問題似乎發生在defrule btwn100and120在CLIPS中使用邏輯運算符

(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)) 
) 

回答

4

使用test函數進行數值比較。另請注意,CLIPS爲數學運算符使用前綴符號。下面是一個簡單的規則,你想要做什麼:

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

這裏是規則的測試:

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>