我想在LHS中使用一个变量绑定来声明规则的突出性,以便按照事实数据库中定义的更严格的时间限制来确定规则的优先级。我认为以下应该有效:
(set-salience-evaluation when-activated)
(deffunction testsal (?a ?b) (integer (+ ?a ?b)))
(defrule testr
(declare (salience (testsal ?a 4)))
(sal ?a)
?tf <- (fire testr)
=>
(printout t "Running testr")
(retract ?tf)
)
(assert (sal 3))
(assert (fire testr))
但是失败并出现错误:
[EVALUATN1] Variable a is unbound
[PRCCODE6] This error occurred while evaluating arguments for the deffunction testsal.
[PRNTUTIL8] This error occurred while evaluating the salience for defrule testr.
ERROR:
(defrule MAIN::testr
(declare (salience (testsal ?a 4)
有没有办法在规则的突出声明中使用LHS中绑定的变量?
如果没有,根据事实基础中的某些事实确定优先次序的常用方法是什么?请注意,我不想禁止触发规则,我只想优先考虑其他规则,因此简单地向LHS添加约束可能不起作用。
答案 0 :(得分:0)
使用全局变量而不是事实:
CLIPS> (set-salience-evaluation when-activated)
when-activated
CLIPS> (defglobal ?*sal-a* = 0)
CLIPS>
(defrule testr
(declare (salience (+ ?*sal-a* 4)))
?tf <- (fire testr)
=>
(printout t "Running testr")
(retract ?tf))
CLIPS> (bind ?*sal-a* 3)
3
CLIPS> (assert (fire testr))
<Fact-1>
CLIPS> (agenda)
7 testr: f-1
For a total of 1 activation.
CLIPS>