CLIPS:修改实例不会触发模式匹配
CLIPS: modify-instance does not trigger pattern matching
有文件test.clp:
(defclass TestClass (is-a USER)
(role concrete)
(pattern-match reactive)
(slot value)
(slot threshold))
(definstances TestObjects
(Test of TestClass
(value 0)
(threshold 3)))
(defrule above-threshold
?test <- (object (is-a TestClass))
(test (> (send ?test get-value) (send ?test get-threshold)))
=>
(printout t "*** Above threshold!! ***" crlf)
(refresh below-threshold))
(defrule below-threshold
?test <- (object (is-a TestClass))
(test (> (send ?test get-value) (send ?test get-threshold)))
=>
(printout t "*** Back to normal ***" crlf)
(refresh above-threshold))
我加载文件并:
CLIPS> (reset)
CLIPS> (agenda)
0 below-threshold: [Test]
For a total of 1 activation.
CLIPS> (run)
*** Back to normal ***
CLIPS> (modify-instance [Test] (value 8))
TRUE
CLIPS> (agenda)
CLIPS>
议程没有显示任何活动规则。我希望将值更改(修改实例)为 8 会触发模式匹配,并且将为 运行 选择规则 "above-threshold" 并将其放入议程。我错过了什么?
来自基本编程指南的第 5.4.1.7 节,与对象模式的模式匹配:
When an instance is created or deleted, all patterns applicable to
that object are updated. However, when a slot is changed, only those
patterns that explicitly match on that slot are affected.
所以修改规则来显式匹配你想要触发模式匹配的槽:
(defrule above-threshold
?test <- (object (is-a TestClass)
(value ?value)
(threshold ?threshold))
(test (> ?value ?threshold))
=>
(printout t "*** Above threshold!! ***" crlf)
(refresh below-threshold))
(defrule below-threshold
?test <- (object (is-a TestClass)
(value ?value)
(threshold ?threshold))
(test (< ?value ?threshold))
=>
(printout t "*** Back to normal ***" crlf)
(refresh above-threshold))
有文件test.clp:
(defclass TestClass (is-a USER)
(role concrete)
(pattern-match reactive)
(slot value)
(slot threshold))
(definstances TestObjects
(Test of TestClass
(value 0)
(threshold 3)))
(defrule above-threshold
?test <- (object (is-a TestClass))
(test (> (send ?test get-value) (send ?test get-threshold)))
=>
(printout t "*** Above threshold!! ***" crlf)
(refresh below-threshold))
(defrule below-threshold
?test <- (object (is-a TestClass))
(test (> (send ?test get-value) (send ?test get-threshold)))
=>
(printout t "*** Back to normal ***" crlf)
(refresh above-threshold))
我加载文件并:
CLIPS> (reset)
CLIPS> (agenda)
0 below-threshold: [Test]
For a total of 1 activation.
CLIPS> (run)
*** Back to normal ***
CLIPS> (modify-instance [Test] (value 8))
TRUE
CLIPS> (agenda)
CLIPS>
议程没有显示任何活动规则。我希望将值更改(修改实例)为 8 会触发模式匹配,并且将为 运行 选择规则 "above-threshold" 并将其放入议程。我错过了什么?
来自基本编程指南的第 5.4.1.7 节,与对象模式的模式匹配:
When an instance is created or deleted, all patterns applicable to that object are updated. However, when a slot is changed, only those patterns that explicitly match on that slot are affected.
所以修改规则来显式匹配你想要触发模式匹配的槽:
(defrule above-threshold
?test <- (object (is-a TestClass)
(value ?value)
(threshold ?threshold))
(test (> ?value ?threshold))
=>
(printout t "*** Above threshold!! ***" crlf)
(refresh below-threshold))
(defrule below-threshold
?test <- (object (is-a TestClass)
(value ?value)
(threshold ?threshold))
(test (< ?value ?threshold))
=>
(printout t "*** Back to normal ***" crlf)
(refresh above-threshold))