next up previous

10.6 MODULES AND RULE EXECUTION

Each module has its own pattern-matching network for its rules and its own agenda. When a run command is given, the agenda of the module which is the current focus is executed (note that the reset and clear commands make the MAIN module the current focus). Rule execution continues until another module becomes the current focus, no rules are left on the agenda, or the return function is used from the RHS of a rule. Whenever a module that was focused on runs out of rules on its agenda, the current focus is removed from the focus stack and the next module on the focus stack becomes the current focus. Before a rule executes, the current module is changed to the module in which the executing rule is defined (the current focus). The current focus can be changed by using the focus command. See sections 5.2, 5.4.10.2, 12.12, and 13.12 for more details.

Example

CLIPS> (clear)
CLIPS> (defmodule MAIN (export ?ALL))
CLIPS>
(defrule MAIN::focus-example
  =>
  (printout t "Firing rule in module MAIN." crlf)
  (focus A B))
CLIPS>
(defmodule A (import MAIN deftemplate initial-fact))
CLIPS>
(defrule A::example-rule
  =>
  (printout t "Firing rule in module A." crlf))
CLIPS>
(defmodule B (import MAIN deftemplate initial-fact))
CLIPS>
(defrule B::example-rule
  =>
  (printout t "Firing rule in module B." crlf))
CLIPS> (reset)
CLIPS> (run)
Firing rule in module MAIN.
Firing rule in module A.
Firing rule in module B.
CLIPS>



next up previous