2016-10-26 9 views
0

私はスロットの制限されたオプションを持つクラスを定義した:私は「ZZZ」(許可されていない)のために文句をクリップを期待、それはなかったクリップ:許可シンボル

(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)  
) 

。どうして?

よろしくお願いいたします。 Nicola

答えて

2

制約チェックは静的(解析中)および動的(実行中)に実行されます。デフォルトでは、静的制約チェックのみが有効です。メッセージハンドラの実行中に不正な値が正当な値に置き換えられる可能性があるため、メッセージの受け渡し時にインスタンスのスロット割り当てが動的に行われます。

実行時に無効な値を置き換えることができるため、定義時に定義をエラーにすることはありませんが、オブジェクトパターンは使用しないで直接スロットの値を取得するためエラーが発生しますメッセージの受け渡し。

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>