next up previous

11.6 CONSTRAINT VIOLATION EXAMPLES

The following examples illustrate some of the types of constraint violations that CLIPS can detect.

Example 1

CLIPS>
(deftemplate bar
   (slot a (type SYMBOL INTEGER))
   (slot b (type INTEGER FLOAT))
   (slot c (type SYMBOL STRING)))
CLIPS>
(defrule error
  (bar (a ?x))
  (bar (b ?x))
  (bar (c ?x))
  =>)
[RULECSTR1] Variable ?x in CE #3 slot c
has constraint conflicts which make the pattern unmatchable
ERROR:
(defrule error-4
   (bar (a ?x))
   (bar (b ?x))
   (bar (c ?x))
   =>)
CLIPS>

The first occurrence of the variable ?x in slot a of the first pattern restricts its allowed types to either a symbol or integer. The second occurrence of ?x in slot b of the second pattern further restricts its allowed types to only integers. The final occurence of ?x in the third pattern generates an error because slot c expects ?x to be either a symbol of a string, but its only allowed type is an integer.

Example 2

CLIPS>
(deftemplate foo (multislot x (cardinality ?VARIABLE 3)))
CLIPS>
(deftemplate bar (multislot y (cardinality ?VARIABLE 2)))
CLIPS>
(deftemplate woz (multislot z (cardinality 7 ?VARIABLE)))
CLIPS>
(defrule error
   (foo (x $?x))
   (bar (y $?y))
   (woz (z $?x $?y))
   =>)
[CSTRNCHK1] The group of restrictions found in CE #3
do not satisfy the cardinality restrictions for slot z
ERROR:
(defrule error
   (foo (x $?x))
   (bar (y $?y))
   (woz (z $?x $?y))
   =>)
CLIPS>

The variable ?x, found in the first pattern, can have a maximum of two fields. The variable ?y, found in the second pattern, can have a maximum of three fields. Added together, both variables have a maximum of five fields. Since slot z in the the third pattern has a minimum cardinality of seven, the variables ?x and ?y cannot satisfy the minimum cardinality restriction for this slot.

Example 3

CLIPS> (deftemplate foo (slot x (type SYMBOL)))
CLIPS>
(defrule error
   (foo (x ?x))
   (test (> ?x 10))
   =>)
[RULECSTR2] Previous variable bindings of ?x caused the type restrictions for argument #1 of the expression (> ?x 10)
found in CE #2 to be violated
ERROR:
(defrule error
   (foo (x ?x))
   (test (> ?x 10))
   =>)
CLIPS>

The variable ?x, found in slot x of the first pattern, must be a symbol. Since the > function expects numeric values for its arguments, an error occurs.




next up previous