如何将类槽限制到某个类?

问题描述 投票:0回答:1

例如,我有以下内容:

(defclass ATTRIBUTE (is-a USER)
  (slot name (type STRING)) 
  (slot value (type INTEGER)) 
)

(defclass PROFILE (is-a USER)
  (multislot skills (type ATTRIBUTE)) 
)

我应该如何更改上面的代码才能使其正常工作?

clips
1个回答
0
投票

名称槽是为所有类预定义的,因此您必须将ATTRIBUTE类中的该槽重命名为其他类(例如属性)。由于消息处理程序可以动态更改分配给插槽的值,因此还需要启用动态约束检查。

         CLIPS (6.31 2/3/18)
CLIPS> 
(defclass ATTRIBUTE 
   (is-a USER)
   (slot attribute
      (type STRING)) 
   (slot value
      (type INTEGER)))
CLIPS> 
(defclass PROFILE 
   (is-a USER)
   (multislot skill 
      (type INSTANCE)
      (allowed-classes ATTRIBUTE)))
CLIPS> (set-dynamic-constraint-checking TRUE)
FALSE
CLIPS> (make-instance a1 of ATTRIBUTE)
[a1]
CLIPS> (make-instance p1 of PROFILE (skill 3))
[CSTRNCHK1] (3) for slot skill of instance [p1] found in put-skill primary in class PROFILE
does not match the allowed types.
[PRCCODE4] Execution halted during the actions of message-handler put-skill primary in class PROFILE
FALSE
CLIPS> (make-instance p1 of PROFILE (skill [a1]))
[p1]
CLIPS> (make-instance p2 of PROFILE (skill (instance-address [a1])))
[p2]
CLIPS> (defclass OTHER (is-a USER))
CLIPS> (make-instance o1 of OTHER)
[o1]
CLIPS> (make-instance p3 of PROFILE (skill [o1]))
[CSTRNCHK1] ([o1]) for slot skill of instance [p3] found in put-skill primary in class PROFILE
does not match the allowed classes.
[PRCCODE4] Execution halted during the actions of message-handler put-skill primary in class PROFILE
FALSE
CLIPS> 
© www.soinside.com 2019 - 2024. All rights reserved.