next up previous

9.3.3.11 Constraint Facets

The syntax and functionality of single and multifield constraint facets (attributes) are described in detail in Section 11. Static and dynamic constraint checking for classes and their instances is supported. Static checking is performed when constructs or commands which specify slot information are being parsed. Object patterns used on the LHS of a rule are also checked to determine if constraint conflicts exist among variables used in more that one slot. Errors for inappropriate values are immediately signaled. Static checking is enabled by default. This behavior can be changed using the set-static-constraint-checking function. Dynamic checking is also supported. If dynamic checking is enabled, then new instances have their values checked whenever they are set (e.g. initialization, slot-overrides, and put- access). This dynamic checking is disabled by default. This behavior can be changed using the set-dynamic-constraint-checking function. If an violation occurs when dynamic checking is being performed, then execution will be halted.

Regardless of whether static or dynamic checking is enabled, multifield values can never be stored in single-field slots. Single-field values are converted to a multifield value of length one when storing in a multifield slot. In addition, the evaluation of a function which has no return value is always illegal as a slot value.

Example

CLIPS> (clear)
CLIPS>
(defclass A (is-a USER)
  (role concrete)
  (multislot foo (create-accessor write)
                 (type SYMBOL)
                 (cardinality 2 3)))
CLIPS> (make-instance a of A (foo 45))
[a]
CLIPS> (set-dynamic-constraint-checking TRUE)
FALSE
CLIPS> (make-instance a of A (foo red 5.0))
[CSTRNCHK1] (red 5.0) for slot foo of instance [a] found in put-foo primary in class A does not match the allowed types.
[PRCCODE4] Execution halted during the actions of message-handler put-foo primary in class A
FALSE
CLIPS> (make-instance a of A (foo red))
[CSTRNCHK1] (red) for slot foo of instance [a] found in put-foo primary in class A does not satisfy the cardinality restrictions.
[PRCCODE4] Execution halted during the actions of message-handler put-foo primary in class A
FALSE
CLIPS>


next up previous