next up previous

5.4.1 Pattern Conditional Element

Pattern conditional elements consist of a collection of field constraints, wildcards, and variables which are used to constrain the set of facts or instances which match the pattern CE. A pattern CE is satisfied by each and every pattern entity that satisfies its constraints. Field constraints are a set of constraints that are used to test a single field or slot of a pattern entity. A field constraint may consist of only a single literal constraint, however, it may also consist of several constraints connected together. In addition to literal constraints, CLIPS provides three other types of constraints: connective constraints, predicate constraints, and return value constraints. Wildcards are used within pattern CEs to indicate that a single field or group of fields can be matched by anything. Variables are used to store the value of a field so that it can be used later on the LHS of a rule in other conditional elements or on the RHS of a rule as an argument to an action.

The first field of any pattern must be a symbol and can not use any other constraints. This first field is used by CLIPS to determine if the pattern applies to an ordered fact, a template fact, or an instance. The symbol object is reserved to indicate an object pattern. Any other symbol used must correspond to a deftemplate name (or an implied deftemplate will be created). Slot names must also be symbols and can not contain any other constraints.

For object and deftemplate patterns, a single field slot can only contain one field constraint and that field constraint must only be able to match a single field (no multifield wildcards or variables). A multifield slot can contain any number of field constraints.

The examples and syntax shown in the following sections will be for ordered and deftemplate fact patterns. Section 5.4.1.7 will discuss differences between deftemplate patterns and object patterns. The following constructs are used by the examples.

(deffacts data-facts
  (data 1.0 blue "red")
  (data 1 blue)
  (data 1 blue red)
  (data 1 blue RED)
  (data 1 blue red 6.9))
(deftemplate person
  (slot name)
  (slot age)
  (multislot friends))
(deffacts people
  (person (name Joe) (age 20))
  (person (name Bob) (age 20))
  (person (name Joe) (age 34))
  (person (name Sue) (age 34))
  (person (name Sue) (age 20)))

5.4.1.1 Literal Constraints

5.4.1.2 Wildcards Single and Multifield

5.4.1.3 Variables Single and Multifield

5.4.1.4 Connective Constraints

5.4.1.5 Predicate Constraints

5.4.1.6 Return Value Constraints

5.4.1.7 PatternMatching with Object Patterns

5.4.1.8 PatternAddresses



next up previous