next up previous

12.18.1 Sequence Expansion and Rules

Sequence expansion is allowed on the LHS of rules, but only within function calls. If a variable is specified in a pattern as a single or multifield variable, then all other references to that variable that are not within function calls must also be the same. For example, the following rule is not allowed

(defrule bad-rule-1
  (pattern $?x ?x $?x)
  =>)

The following rules illustrate appropriate use of sequence expansion on the LHS of rules.

(defrule good-rule-1
  (pattern $?x&:(> (length$ ?x) 1))
  (another-pattern $?y&:(> (length$ ?y) 1))
  (test (> (+ $?x) (+ $?y)))
  =>)

The first and second patterns use the length$ function to determine that the multifields bound to ?x and ?y are greater than 1. Sequence expansion is not used to pass ?x and ?y to the length$ function since the length$ function expects a single argument of type multifield. The test CE calls the + function to determine the sum of the values bound to ?x and ?y. Sequence expansion is used for these function calls since the + function expects two or more arguments with numeric data values.

Sequence expansion has no affect within an assert, modify, or duplicate; however, it can be used with other functions on the RHS of a rule.


next up previous