CLIPS编程语言中如何正确使用not条件?
How to use not condition in CLIPS programming language properly?
这是我的代码
(deffacts startup
(bird canary)
(colour-canary yellow)
(bird ostrich)
(can-not-fly ostrich)
)
(defrule r-bird-test
(bird ?var)
(not (bird ostrich))
=>
(printout t ?var " ****" crlf)
)
现在,当我(重置)和(运行)时,它不会打印 "canary ****"。我没有正确使用not条件吗?谁能指出我在这里缺少什么?谢谢
正如所写,如果存在事实(鸟鸵鸟),则非条件元素会阻止规则执行。由于一旦您执行(重置)该事实就存在,因此该规则不会执行。如果您希望对每个 ?var 不是鸵鸟的鸟类事实执行规则,您需要这样编写规则:
CLIPS>
(deffacts startup
(bird canary)
(colour-canary yellow)
(bird ostrich)
(can-not-fly ostrich))
CLIPS>
(defrule r-bird-test
(bird ?var&~ostrich)
=>
(printout t ?var " ****" crlf))
CLIPS> (reset)
CLIPS> (run)
canary ****
CLIPS>
这是我的代码
(deffacts startup
(bird canary)
(colour-canary yellow)
(bird ostrich)
(can-not-fly ostrich)
)
(defrule r-bird-test
(bird ?var)
(not (bird ostrich))
=>
(printout t ?var " ****" crlf)
)
现在,当我(重置)和(运行)时,它不会打印 "canary ****"。我没有正确使用not条件吗?谁能指出我在这里缺少什么?谢谢
正如所写,如果存在事实(鸟鸵鸟),则非条件元素会阻止规则执行。由于一旦您执行(重置)该事实就存在,因此该规则不会执行。如果您希望对每个 ?var 不是鸵鸟的鸟类事实执行规则,您需要这样编写规则:
CLIPS>
(deffacts startup
(bird canary)
(colour-canary yellow)
(bird ostrich)
(can-not-fly ostrich))
CLIPS>
(defrule r-bird-test
(bird ?var&~ostrich)
=>
(printout t ?var " ****" crlf))
CLIPS> (reset)
CLIPS> (run)
canary ****
CLIPS>