next up previous

5.4.5 Not Conditional Element

Sometimes the lack of information is meaningful; i.e., one wishes to fire a rule if a pattern entity or other CE does not exist. The not conditional element provides this capability. The not CE is satisfied only if the conditional element contained within it is not satisfied. As with other conditional elements, any number of additional CEs may be on the LHS of the rule and field constraints may be used within the negated pattern.

Syntax

<not-CE> ::= (not <conditional-element>)

Only one CE may be negated at a time. Multiple patterns may be negated by using multiple not CEs. Care must be taken when combining not CEs with or and and CEs; the results are not always obvious! The same holds true for variable bindings within a not CE. Previously bound variables may be used freely inside of a not CE. However, variables bound for the first time within a not CE can be used only in that pattern.

Examples

(defrule high-flow-rate
   (temp high)
   (valve open)
   (not (error-status confirmed))
   =>
   (printout t "Recommend closing of valve due to high temp"
               crlf))
   (defrule check-valve
   (check-status ?valve)
   (not (valve-broken ?valve))
   =>
   (printout t "Device " ?valve " is OK" crlf))
(defrule double-pattern
   (data red)
   (not (data red ?x ?x))
   =>
   (printout t "No patterns with red green green!" crlf ))

A not CE that contains a single test CE is converted such that the test CE is contained within an and CE and is preceded by the (initialfact) or (initialobject) pattern. For example, the following conditional element

(not (test (> ?time-1 ?time-2)))

is converted to

(not (and (initial-fact)
          (test (> ?time-1 ?time-2))))

Note that it is much simpler just to convert the test CE to the following format:

(test (not (> ?time-1 ?time-2)))


next up previous