CLIPS:允许的符号

CLIPS: allowed-symbol

我定义了一个 class,其中有一个插槽的限制选项:

(defclass TARGET (is-a USER)
    (slot uuid
        (type STRING))
    (slot function
        (type SYMBOL)
        (allowed-symbols a1 a2 b c d e f g))
)

(make-instance target of TARGET
    (uuid "a123")  
    (function zzz)    
)

我希望 CLIPS 会抱怨 "zzz"(不允许),但它没有。为什么?

此致。 尼古拉

约束检查是静态(在解析期间)和动态(在执行期间)完成的。默认情况下,仅启用静态约束检查。当调用消息传递时,实例的插槽分配是动态完成的,因为在执行消息处理程序期间,非法值可能会被合法值替换。

在下面的例子中,definstances在定义时不会产生错误,因为在运行时可以替换无效值,但是defrule确实会产生错误,因为对象模式直接获取值不使用消息传递的插槽。

CLIPS> (clear)
CLIPS> 
(defclass TARGET (is-a USER)
   (slot uuid
      (type STRING))
   (slot function
      (type SYMBOL)
      (allowed-symbols a1 a2 b c d e f g)))
CLIPS> 
(definstances static
   (target1 of TARGET (uuid "a123") (function zzz)))
CLIPS>    
(defrule static
   (object (is-a TARGET) (function zzz))
   =>)

[CSTRNCHK1] A literal restriction value found in CE #1
does not match the allowed values for slot function.

ERROR:
(defrule MAIN::static
   (object (is-a TARGET)
           (function zzz))
   =>)
CLIPS> (reset)
CLIPS>          
(make-instance target2 of TARGET
    (uuid "b456")  
    (function zzz))
[target2]
CLIPS>

如果您启用动态约束检查,您将在实际创建实例时在执行期间看到错误:

CLIPS> (set-dynamic-constraint-checking TRUE)
FALSE
CLIPS> 
(make-instance target3 of TARGET
    (uuid "c789")  
    (function zzz))
[CSTRNCHK1] zzz for slot function of instance [target3] found in put-function primary in class TARGET
does not match the allowed values.
[PRCCODE4] Execution halted during the actions of message-handler put-function primary in class TARGET
FALSE
CLIPS> (reset)
[CSTRNCHK1] zzz for slot function of instance [target1] found in put-function primary in class TARGET
does not match the allowed values.
[PRCCODE4] Execution halted during the actions of message-handler put-function primary in class TARGET
CLIPS>