In CLIPS and if we are using modules then we can use auto-focus for rules in a module:
Auto focus rule property allows an automatic focus command to be executed whenever a rule becomes active. If the auto focus property for a rule is TRUE, then a focus command on the module which the rule is defined is automatically executed whenever the rule is activated.
My question is that:
If I have two modules A and B, where B has a rule with an auto-focus property and currently I am at module A, the rule in B is activated and because of the "auto-focus property" module B is activated automatically , after the rule is executed, will the focus be back to module A or ?
When you focus on a module (using either the focus command or auto-focus), the module is pushed onto a stack. When the rules in that module have finished, the current focus will be popped from the stack and the prior module will now have focus. So in your example, the focus would return to module A once there are no more rules on the agenda in module B.
CLIPS (6.4.1 4/8/23)
CLIPS> (defmodule A (export ?ALL))
CLIPS> (deftemplate flag)
CLIPS> (defrule a1 => (assert (flag)))
CLIPS> (defrule a2 (flag) => (println "a2"))
CLIPS> (defmodule B (import A ?ALL))
CLIPS> (defrule b1 (declare (auto-focus TRUE)) (flag) => (println "b1"))
CLIPS> (reset)
CLIPS> (focus A)
TRUE
CLIPS> (list-focus-stack)
A
MAIN
CLIPS> (agenda)
0 a1: *
For a total of 1 activation.
CLIPS> (run 1)
CLIPS> (agenda *)
MAIN:
A:
0 a2: f-1
B:
0 b1: f-1
For a total of 2 activations.
CLIPS> (list-focus-stack)
B
A
MAIN
CLIPS> (run 1)
b1
CLIPS> (list-focus-stack)
A
MAIN
CLIPS> (run)
a2
CLIPS>