如何断言与匹配相反的值?
How to assert the opposite value from that of the matching?
我有一个规则,它有一个插槽可以与两种颜色进行匹配,只要匹配后它变成相反的颜色,它匹配哪一种并不重要。但是当我写这个的时候,我得到一个语法错误:
(defrule colour
?col <- (colorTemp(color ?color&white|black))
=>
(modify ?col (color ?colorOpposite&~?color))
)
谢谢
语法 ?colorOpposite&~?color 在规则的操作中无效,并且变量 ?colorOpposite 未绑定在规则的任何位置,因此这两个问题都会产生错误。您还需要添加一些代码来指定颜色的对立面。为防止从一个相反的循环到另一个,您将需要以某种方式指示颜色已更改。
CLIPS (6.31 6/12/19)
CLIPS>
(deftemplate colorTemp
(slot color)
(slot changed (default no)))
CLIPS>
(deffacts opposites
(opposite white black))
CLIPS>
(defrule colour
?col <- (colorTemp (color ?color&white|black)
(changed no))
(or (opposite ?color ?opposite)
(opposite ?opposite ?color))
=>
(modify ?col (color ?opposite)
(changed yes)))
CLIPS> (reset)
CLIPS> (assert (colorTemp (color white)))
<Fact-2>
CLIPS> (facts)
f-0 (initial-fact)
f-1 (opposite white black)
f-2 (colorTemp (color white) (changed no))
For a total of 3 facts.
CLIPS> (agenda)
0 colour: f-2,f-1
For a total of 1 activation.
CLIPS> (run)
CLIPS> (facts)
f-0 (initial-fact)
f-1 (opposite white black)
f-3 (colorTemp (color black) (changed yes))
For a total of 3 facts.
CLIPS>
我有一个规则,它有一个插槽可以与两种颜色进行匹配,只要匹配后它变成相反的颜色,它匹配哪一种并不重要。但是当我写这个的时候,我得到一个语法错误:
(defrule colour
?col <- (colorTemp(color ?color&white|black))
=>
(modify ?col (color ?colorOpposite&~?color))
)
谢谢
语法 ?colorOpposite&~?color 在规则的操作中无效,并且变量 ?colorOpposite 未绑定在规则的任何位置,因此这两个问题都会产生错误。您还需要添加一些代码来指定颜色的对立面。为防止从一个相反的循环到另一个,您将需要以某种方式指示颜色已更改。
CLIPS (6.31 6/12/19)
CLIPS>
(deftemplate colorTemp
(slot color)
(slot changed (default no)))
CLIPS>
(deffacts opposites
(opposite white black))
CLIPS>
(defrule colour
?col <- (colorTemp (color ?color&white|black)
(changed no))
(or (opposite ?color ?opposite)
(opposite ?opposite ?color))
=>
(modify ?col (color ?opposite)
(changed yes)))
CLIPS> (reset)
CLIPS> (assert (colorTemp (color white)))
<Fact-2>
CLIPS> (facts)
f-0 (initial-fact)
f-1 (opposite white black)
f-2 (colorTemp (color white) (changed no))
For a total of 3 facts.
CLIPS> (agenda)
0 colour: f-2,f-1
For a total of 1 activation.
CLIPS> (run)
CLIPS> (facts)
f-0 (initial-fact)
f-1 (opposite white black)
f-3 (colorTemp (color black) (changed yes))
For a total of 3 facts.
CLIPS>