CLIPS: allowed-symbol -
i defined class restricted options slot:
(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) )
i expected clips complain "zzz" (not allowed), didn't. why?
best regards. nicola
constraint checking done statically (during parsing) , dynamically (during execution). default, static constraint checking enabled. slot assignments instances done dynamically when messages passing invoked because it's possible illegal value replaced legal value during execution of message handler.
in following case, definstances not generate error when defined because invalid value replaced @ run time, defrule generate error because object patterns directly grab value of slot without using message passing.
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] literal restriction value found in ce #1 not match allowed values 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>
if enable dynamic constraint checking, you'll see errors during execution when instances created:
clips> (set-dynamic-constraint-checking true) false clips> (make-instance target3 of target (uuid "c789") (function zzz)) [cstrnchk1] zzz slot function of instance [target3] found in put-function primary in class target not match allowed values. [prccode4] execution halted during actions of message-handler put-function primary in class target false clips> (reset) [cstrnchk1] zzz slot function of instance [target1] found in put-function primary in class target not match allowed values. [prccode4] execution halted during actions of message-handler put-function primary in class target clips>
Comments
Post a Comment