【问题标题】:CLIPS: retrieve slot value from multislot if INSTANCESCLIPS:如果是实例,则从多槽中检索槽值
【发布时间】:2016-12-12 17:25:21
【问题描述】:

我有一个带有多槽实例的对象。 我在一次调用获得实例的插槽时遇到问题。 示例:

(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.
FALSE

2) 尝试使用“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) 命令。 有什么建议吗?

谢谢 尼克

【问题讨论】:

    标签: clips


    【解决方案1】:

    First$ 返回一个多字段值,而 implode$ 返回一个字符串。您需要使用实例名称。使用 nth$ 从多字段中检索字段。您还需要保持实例名称的大小写一致:

    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>
    

    【讨论】:

      猜你喜欢
      • 2014-07-01
      • 2014-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-07
      • 1970-01-01
      • 2020-01-17
      相关资源
      最近更新 更多