CLIPS - 如何获得特定事实的价值?

时间:2014-09-21 17:38:27

标签: if-statement clips

我想使用CLIPS创建一个if-then-else函数但是我的条件语句存在问题。

示例事实:

f-0     (initial-fact)
f-1     (green-peppers yes)

是否有可能获得青椒的价值(是)所以我可以设置这样的条件?

(if (eq <fact-1> "yes")
   then 
   (assert)
)

谢谢!

1 个答案:

答案 0 :(得分:0)

CLIPS> (clear)
CLIPS> (assert (green-peppers yes))
<Fact-1>
CLIPS> (assert (green-peppers no))
<Fact-2>
CLIPS> 
(deffunction need (?f)
   (bind ?v (nth$ 1 (fact-slot-value ?f implied)))
   (if (eq ?v yes)
      then TRUE
      else FALSE))
CLIPS> (need 1)
TRUE
CLIPS> (need 2)
FALSE
CLIPS> (clear)
CLIPS> (deftemplate green-peppers (slot need))
CLIPS> (assert (green-peppers (need yes)))
<Fact-1>
CLIPS> (assert (green-peppers (need no)))
<Fact-2>
CLIPS> 
(deffunction need (?f)
   (if (eq (fact-slot-value ?f need) yes)
      then TRUE
      else FALSE))
CLIPS> (need 1)
TRUE
CLIPS> (need 2)
FALSE
CLIPS>