【发布时间】:2015-02-19 11:18:46
【问题描述】:
我想写一条这样的规则
if x > y => assert x
其中x 和y 是变量,它们的值作为事实给出。
我该怎么做?
【问题讨论】:
标签: clips
我想写一条这样的规则
if x > y => assert x
其中x 和y 是变量,它们的值作为事实给出。
我该怎么做?
【问题讨论】:
标签: clips
如果 x 已经作为一个事实存在,那么从规则的操作中再次断言它是不必要的,但是如果你想断言一个表明 x 大于 y 的事实,那么你可以这样做:
CLIPS>
(defrule greater-than
(x ?x)
(y ?y)
(test (> ?x ?y))
=>
(assert (x-is-greater-than-y)))
CLIPS> (assert (x 4))
<Fact-1>
CLIPS> (assert (y 1))
<Fact-2>
CLIPS> (agenda)
0 greater-than: f-1,f-2
For a total of 1 activation.
CLIPS> (run)
CLIPS> (facts)
f-0 (initial-fact)
f-1 (x 4)
f-2 (y 1)
f-3 (x-is-greater-than-y)
For a total of 4 facts.
CLIPS>
【讨论】: