2015-05-19 72 views
0

我想如果用戶定義使用(讀取)功能遞增用戶中的全局變量回答defrule

(defrule QPain 
     (initial-fact) 
     => 
     (printout t "Are You In Pain? " crlf) 
     (bind (ans Answer) (read)) 
     ) 
(defrule AnsInc 
     (Answ Answer = "y") 
     => 
     (bind ?*symcount* (+ ?*symcount* 1))) 

的增加,他們有疼痛遞增通過1 defglobal變量(symcount)必須僅在用戶按下「y」 時發生,否則增量不得發生。

+0

的可能重複[如何比較在剪輯字符串中的全局變量?](http://stackoverflow.com/questions/30324191/how-to-compare-a-global-variable-to-一個字符串,在剪輯) –

回答

0
CLIPS> (defglobal ?*symcount* = 0) 
CLIPS> 
(defrule QPain 
    => 
    (printout t "Are You In Pain? ") 
    (bind ?answer (read)) 
    (if (eq ?answer y) 
     then 
     (bind ?*symcount* (+ ?*symcount* 1)))) 
CLIPS> (reset) 
CLIPS> (run) 
Are You In Pain? y 
CLIPS> ?*symcount* 
1 
CLIPS> (reset) 
CLIPS> (run) 
Are You In Pain? n 
CLIPS> ?*symcount* 
0 
CLIPS>