如何编写规则来检测剪辑中实例的删除?
这就是我目前所拥有的:
(defclass classA (is-a USER) (role concrete))
(defclass classB (is-a USER) (role concrete)
(slot a (type INSTANCE)))
(defrule classA-delete
?binstance <- (object (is-a classB) (a ?a&~:(instance-existp ?a)))
=>
(send ?binstance delete))
但是当我删除 classA 的实例时,规则不会触发。
This is what I currently have:
(defclass classA (is-a USER) (role concrete))
(defclass classB (is-a USER) (role concrete)
(slot a (type INSTANCE)))
(defrule classA-delete
?binstance <- (object (is-a classB) (a ?a&~:(instance-existp ?a)))
=>
(send ?binstance delete))
But the rule does not fire when I delete an instance of classA.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
模式匹配过程并不具体了解什么可能会影响规则 LHS 上谓词函数的评估结果(在本例中为 instance-existp 函数)。在这种情况下,您的规则仅与 classB 的实例匹配,因此只有对该实例的更改才会重新触发模式匹配。当 classB 实例最初匹配时,将对 instance-existp 函数进行评估,要么成功,要么失败。更改 a 槽的值将重新触发 instance-existp 评估,但对规则中模式中未包含的实例或实例槽的更改将不会重新触发模式匹配。如果您使用非条件元素来检查实例,您将得到您想要的行为:
The pattern matching process doesn't have specific knowledge of what may effect the result of the evaluation of a predicate function on the LHS of a rule (in this case the instance-existp function). In this case, your rule only matches against instances of classB, so only changes to that instance are going to retrigger pattern matching. When the classB instance is originally matched, the instance-existp function is evaluated and either succeeds or fails. Changing the value of the a slot will retrigger the instance-existp evaluation, but changes to an instance or instance slot that is not contained within a pattern in the rule will not retrigger pattern matching. If you use the not conditional element to check for the instance, you'll get the behavior you want: