CLIPS incrementing a variable with a rule

烈酒焚心 提交于 2019-12-12 19:10:00

问题


I want to increment security when the rule is run. Right now it changes nothing. The fact (human_resources n) does exist.

(defglobal ?security = 0)

(defrule rule1 (human_resources n) => (defglobal ?security = (+ ?security 1)) )

This results in ?*security = 1: (defglobal ?security = 0) (defglobal ?security = (+ ?security 1))


回答1:


CLIPS> (defglobal ?*security* = 0)
CLIPS> 
(defrule rule1
   (human_resources n)
   =>
   (bind ?*security* (+ ?*security* 1)))
CLIPS> (reset)
CLIPS> ?*security*
0
CLIPS> (assert (human_resources n))
<Fact-1>
CLIPS> (run)
CLIPS> ?*security*
1
CLIPS> 


来源:https://stackoverflow.com/questions/5718243/clips-incrementing-a-variable-with-a-rule

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!