我有一个带有多槽实例的对象。我在一次调用中获取实例的插槽时遇到问题。示例:
(defclass AUTOMA (is-a USER)
(slot uuid))
(defclass TUTOMA (is-a USER)
(multislot list
(type INSTANCE)))
(make-instance A1 of AUTOMA
(uuid a1))
(make-instance A2 of AUTOMA
(uuid a2))
(make-instance T1 of TUTOMA
(list [a1] [a2]))我想检索多槽列表的第一个对象uuid。
1)尝试使用"first$":
CLIPS> (first$ (send [T1] get-list))
([a1])
CLIPS> (send (first$ (send [T1] get-list)) get-uuid)
[MSGFUN1] No applicable primary message-handlers found for get-uuid.
FALSE2)尝试使用"implode$":
CLIPS> (implode$ (first$ (send [T1] get-list)))
"[a1]"
CLIPS> (send (implode$ (first$ (send [T1] get-list))) get-uuid)
[MSGFUN1] No applicable primary message-handlers found for get-uuid.
FALSE似乎(a1)和"a1“都不适合(send XXX get-uuid)命令。有什么建议吗?
谢谢你,Nic
发布于 2016-12-13 06:54:05
首先$返回一个多字段值,而implode$返回一个字符串。您需要使用实例名称。使用第n$从多字段中检索字段。您还需要保持实例名称使用的大小写一致:
CLIPS>
(defclass AUTOMA
(is-a USER)
(slot uuid))
CLIPS>
(defclass TUTOMA
(is-a USER)
(multislot list (type INSTANCE)))
CLIPS> (make-instance A1 of AUTOMA (uuid a1))
[A1]
CLIPS> (make-instance A2 of AUTOMA (uuid a2))
[A2]
CLIPS> (make-instance T1 of TUTOMA (list [A1] [A2]))
[T1]
CLIPS> (send (nth$ 1 (send [T1] get-list)) get-uuid)
a1
CLIPS>https://stackoverflow.com/questions/41106225
复制相似问题