【发布时间】:2021-06-21 18:56:47
【问题描述】:
当我们定义 rule 时,我们可以在pattern 和action 区域(assert 所在的位置)中拥有相同的槽 名称吗?我用下面的代码举例:
(deftemplate b1
(slot s1)
(slot s2))
(deftemplate b2
(slot s1)
(slot s2))
(deftemplate b3
(slot r1)
(slot r2))
(deftemplate b4
(slot r1)
(slot r2))
; Facts
(deffacts F
(b1 (s1 2)(s2 5))
(b2 (s1 7)(s2 9)))
; Rules
(defrule R1
(b1 (s1 ?x1)(s2 ?y1))
(b2 (s1 ?x2)(s2 ?y2))
=>
(assert (b4(r1 (* ?x1 ?x2))(r2 (* ?y1 ?y2))))
(printout t)
)
(defrule R2
(b2 (s1 ?x1)(s2 ?y1))
(b3 (r1 ?x2)(r2 ?y2))
=>
(assert (b3(r1 (* ?x1 ?x2))(r2 (* ?y1 ?y2))))
(printout s)
)
我描述的情况位于代码的R2规则中。当我运行程序时,我看到只有规则R1 被执行。是因为这条线吗?
(b3 (r1 ?x2)(r2 ?y2))
=>
(assert (b3(r1 (* ?x1 ?x2))(r2 (* ?y1 ?y2))))
因为我们已经使用了两次 r1,就像我之前说的那样。
【问题讨论】: