CLIPS错误:清理时非法使用模块说明符

时间:2020-04-09 16:09:10

标签: rules rule-engine clips expert-system

我想定义一些模块规则来断言模块事实,然后按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

为什么出现语法错误?如何为defrule的{​​{1}}做此事?

1 个答案:

答案 0 :(得分:1)

不要在assert命令中使用M :: T。由于该碎片包含在模块M中,因此无需使用模块说明符就可以引用M可见的所有deftemplate。

         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>