CLIPS模式匹配中的数字相等性测试失败? [英] Number equality test fails in CLIPS pattern matching?

查看:100
本文介绍了CLIPS模式匹配中的数字相等性测试失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的CLIPS文件中有以下规则:

I have this following rule in my CLIPS file:

(defrule check-final (declare (salience 12))
    ?scnt <- (set-count (value ?v) (class ?c))
    (test (= ?v ?*total*))
    =>
    (printout T ?*total* " == " ?v crlf)
)

我得到以下奇怪的输出:

And I get the following strange output:

CLIPS>(run)
14 == 9
5 == 2

这怎么可能????

推荐答案

只要声明或修改了事实set-count,就会发生与此规则的模式匹配.在调用run的过程中,此规则会在之后的某个时间触发.这两个过程可以在时间上广泛分离. ?*v*的值当然可以在很长一段时间内发生变化.

Pattern matching for this rule occurs whenever the fact set-count is asserted or modified. The rule is fired some time afterwards, during the call to run. These two processes can be widely separated in time. The value of ?*v* can of course change during that long period of time.

关键是要意识到他打印的结果将反映发生模式匹配的时期的?v值,而?*total*是打印结果时的值.由于?*total*自模式匹配以来可能已经发生了任意变化,因此不能保证在规则实际触发时它等于?v.

The key is to realize that he printed results will reflect the value of ?v from the the epoch during which pattern matching happened, while ?*total* will be the value when the results are printed. Since ?*total* may have seen arbitrary changes since the pattern matching, there's no guarantee that it will be equal to ?v when the rule actually fires.

这篇关于CLIPS模式匹配中的数字相等性测试失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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