0

这是我目前拥有的:

(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 的实例时,该规则不会触发。

4

1 回答 1

0

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:

(defclass classA (is-a USER) 
                 (role concrete))

(defclass classB (is-a USER) 
                 (role concrete)
                 (slot a (type INSTANCE)))

(definstances start
   (a of classA)
   (b of classB (a [a])))  

(defrule classA-delete
  ?binstance <- (object (is-a classB) (a ?a))
  (not (object (name ?a)))
  =>
  (send ?binstance delete))
于 2012-03-16T04:09:56.523 回答