CLIPS访问属性的属性 [英] CLIPS accessing a property of a property

查看:93
本文介绍了CLIPS访问属性的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读了答案是

更好地通过匹配来显式检索插槽值 而不是使用插槽访问器,因为这将导致出现以下情况: 每当广告位值更改时,都会重新评估

better to explicitly retrieve the slot value by matching it rather than using the slot accessor as this will cause the condition to be reevaluated whenever the slot value changes

如果我要访问某个物业的物业怎么办?例如,

What if I want to access the property of a property? For example,

分别给出了类AB的两个实例ab.

given two instances a and b of classes A and B, respectively.

a具有一个名为ref_to_b的属性,该属性是对b的引用. b具有一个名为some_prop_of_b的属性.

a has a property called ref_to_b which is a reference to b. b has a property called some_prop_of_b.

我如何匹配以下内容:

a,其中ref_to_b等于bsome_prop_of_b等于"some_string".

a with ref_to_b equal to b and some_prop_of_b equal to "some_string".

我尝试了此操作,但出现了错误:

I tried this but got an error:

(defrule my_rule "comment me"
    (object (is-a A)
        (ref_to_b ?ref_to_b))
    (?ref_to_b
        (some_prop_of_b "some_string"))
=>
)

推荐答案

将引用实例的实例名称放在ref_to_b插槽中,然后使用名称插槽来匹配引用:

Place the instance name of the referenced instance in the ref_to_b slot and then use the name slot to match the reference:

CLIPS> 
(defclass A (is-a USER) (slot ref_to_b))
CLIPS> 
(defclass B (is-a USER) (slot some_prop_of_b))
CLIPS> 
(make-instance [b1] of B (some_prop_of_b "some_string"))
[b1]
CLIPS> 
(make-instance [b2] of B (some_prop_of_b "not_some_string"))
[b2]
CLIPS> 
(make-instance [a] of A (ref_to_b [b2]))
[a]
CLIPS> 
(defrule my_rule
   (object (is-a A) (ref_to_b ?name_b))
   (object (name ?name_b) (some_prop_of_b "some_string"))
   =>)
CLIPS> (agenda)
CLIPS> (send [a] put-ref_to_b [b1])
[b1]
CLIPS> (agenda)
0      my_rule: [a],[b1]
For a total of 1 activation.
CLIPS> 

这篇关于CLIPS访问属性的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆