在 Defrule 中查找与条件匹配的所有事实
Find all facts matching a condition in Defrule
我有两种类型的事实:state1 和 state2,都是数字数组。我想检查是否存在带有标签 'state' 且当前值为 state2 变量的事实。我该怎么做?
例如,如果现在事实是:
状态 1 2 3
状态 2 4 5 6
状态 0 8 9,
当前 state2 是 1 2 3,我想进入 RHS,因为第一行 'State 1 2 3' 匹配 State2 的当前值。
我尝试了以下解决方案,但我从未输入 RHS。
;;; END FUNCTION, EXECUTES WHEN SOLUTION WAS FOUND
(defrule complete (declare (salience 1000))
(exists (state ?state2))
=> (printout t "Target state [1 2 3 8 0 4 7 6 5] reached" crlf) (halt)
);
CLIPS (6.31 6/12/19)
CLIPS>
(defrule complete
(exists (state $?state)
(state2 $?state))
=>
(printout t "Target state [1 2 3 8 0 4 7 6 5] reached" crlf))
CLIPS>
(assert
(state 1 2 3)
(state2 4 5 6)
(state 0 8 9)
(state2 1 2 3))
<Fact-4>
CLIPS> (agenda)
0 complete: *
For a total of 1 activation.
CLIPS> (run)
Target state [1 2 3 8 0 4 7 6 5] reached
CLIPS>
我有两种类型的事实:state1 和 state2,都是数字数组。我想检查是否存在带有标签 'state' 且当前值为 state2 变量的事实。我该怎么做?
例如,如果现在事实是:
状态 1 2 3
状态 2 4 5 6
状态 0 8 9,
当前 state2 是 1 2 3,我想进入 RHS,因为第一行 'State 1 2 3' 匹配 State2 的当前值。
我尝试了以下解决方案,但我从未输入 RHS。
;;; END FUNCTION, EXECUTES WHEN SOLUTION WAS FOUND
(defrule complete (declare (salience 1000))
(exists (state ?state2))
=> (printout t "Target state [1 2 3 8 0 4 7 6 5] reached" crlf) (halt)
);
CLIPS (6.31 6/12/19)
CLIPS>
(defrule complete
(exists (state $?state)
(state2 $?state))
=>
(printout t "Target state [1 2 3 8 0 4 7 6 5] reached" crlf))
CLIPS>
(assert
(state 1 2 3)
(state2 4 5 6)
(state 0 8 9)
(state2 1 2 3))
<Fact-4>
CLIPS> (agenda)
0 complete: *
For a total of 1 activation.
CLIPS> (run)
Target state [1 2 3 8 0 4 7 6 5] reached
CLIPS>