HANDBOOK / GENTLE PRIMER / Optimal Rule Selection /

# The Two Processing Phases

Rules of `choice` predicates are processed in two phases: in the first phase, the optimal rule combination is determined; in the second phase, these rules are elaborated just as for ordinary predicates.

To determine which rules should be applied, the first phase performs pattern matching and evaluates conditions. Conditions invoked from rules of `choice` predicates should only test their arguments, but must have no side effects such as changing global variables.

In the second phase, only those rules are elaborated that were selected in the first phase. During rule elaboration, now also predicates of the category `action` are invoked. These invocations may have side effects, such as emitting code.