The allowed-classes attribute is very aggressive enforcing its restrictions. For example, you can place an instance name in the object slot if an instance exists so that its class can be determined:
CLIPS (6.31 6/12/19)
CLIPS> (clear)
CLIPS>
(defclass command
(is-a USER))
CLIPS>
(defclass command_data
(is-a USER)
(slot object
(allowed-classes command)))
CLIPS> (make-instance [c1] of command)
[c1]
CLIPS>
(defrule no-error
(object
(is-a command_data)
(object [c1]))
=>)
CLIPS>
But if you use an instance name for an instance that has not yet been created and so its class cannot be determined, you'll get an error:
CLIPS>
(defrule triggers-static-error
(object
(is-a command_data)
(object [c2]))
=>)
[CSTRNCHK1] A literal restriction value found in CE #1
does not match the allowed classes for slot object.
ERROR:
(defrule MAIN::triggers-static-error
(object (is-a command_data)
(object [c2]))
=>)
CLIPS>
The simplest way to fix this is to disable static constraint checking:
CLIPS> (set-static-constraint-checking FALSE)
TRUE
CLIPS>
(defrule no-longer-triggers-static-error
(object
(is-a command_data)
(object [c2]))
=>)
CLIPS>
You can also remove the allowed-classes attribute from your classes or modify your rule so that the instance name constant is not referenced inside the slot pattern:
CLIPS> (set-static-constraint-checking TRUE)
FALSE
CLIPS>
(defrule no-longer-triggers-static-error
(object
(is-a command_data)
(object ?o))
(test (eq ?o [c2]))
=>)
CLIPS>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…