一、完成从MAIN->NO1->NO2模块变化
CLIPS> (clear)
CLIPS> (defmodule MAIN
(export deftemplate initial-fact))
CLIPS> (defmodule NO1
(import MAIN deftemplate initial-fact))
CLIPS> (defrule MAIN::START
=>(focus NO1))
CLIPS> (defrule NO1::next
=>
(printout t "begin no1" crlf)
(focus NO2)
(return)
(printout t "end no1" crlf))
CLIPS> (defmodule NO2)
CLIPS> (get-current-module)
NO2
CLIPS> (defrule NO2:next2
=>
(printout t "begin no2 " crlf)
(pop-focus)
(printout t "end no2" crlf)
)
CLIPS> (watch rules)
CLIPS> (watch focus)
CLIPS> (reset)
<== Focus MAIN
==> Focus MAIN
CLIPS> (run)
FIRE 1 START:*
==> Focus NO1 from MAIN
FIRE 2 next:*
begin no1
==> Focus NO2 from NO1
<== Focus NO1
FIRE 3NO2:next2: *
begin no2
<== Focus NO2 to MAIN
end no2
<== Focus MAIN
CLIPS>
二、当前焦点是称为焦点栈的堆栈数据结构的顶点值,用focus改变当前焦点,实际上就是交新的焦点移到焦点栈的顶部,取代原焦点,随着规则的执行,当前焦点的议程为空时,当前焦点将从焦点栈中弹出,同时此时位于栈顶的另一模块成为当前焦点,该焦点的议程被执行。
1、(get-current-module)得到当前模块
2、(list-focus-stack)列出模块堆栈
3、(defmodule NO2)定义模块
4、(pop-focus)为从栈中弹出当前焦点模块,但允许规则的RHS操作继续执行,因为end no2被打印出。
5、(return)为从栈中弹出当前焦点模块并返回,所以规则的RHS操作不会继续执行,end no1没有打印出