CLIPS Error: Illegal use of the module specifier when defrule

CLIPS Error: Illegal use of the module specifier when defrule

我想定义一些模块规则来断言模块事实,然后通过get-fact-list批量获取一组事实列表,但是出现错误!

         CLIPS (6.31 6/12/19)
CLIPS> (defmodule M)
CLIPS> (deftemplate M::T (slot k1))
CLIPS> (defrule M::T (testvalue 1) => (assert (M::T (k1 "v1"))))

[MODULDEF1] Illegal use of the module specifier.

ERROR:
(defrule M::T
   (testvalue 1)
   =>
   (assert (M::T
CLIPS> 

预计:

CLIPS> (defmodule M)
CLIPS> (deftemplate M::T (slot k1))
CLIPS> (defrule M::T (testvalue 1) => (assert (M::T (k1 "v1"))))

CLIPS> (assert (testvalue 1))
CLIPS> (get-fact-list M)
;; return the facts that M::rulexx  assert

为什么语法错误? moduledefrule 怎么办?

不要在断言命令中使用 M::T。由于 defrule 包含在模块 M 中,因此可以在不使用模块说明符的情况下引用所有对 M 可见的 deftemplates。

         CLIPS (6.31 6/12/19)
CLIPS> (defmodule M)
CLIPS> (deftemplate M::T (slot k1))
CLIPS> (defrule M::T (testvalue 1) => (assert (T (k1 "v1"))))
CLIPS> (assert (testvalue 1))
<Fact-1>
CLIPS> (get-fact-list M)
(<Fact-1>)
CLIPS>