每次触发Jess规则时增加或更改变量 [英] Increment or change variable each time Jess rule fires
问题描述
每次触发规则时,是否可以增加或更改某些变量的值? 我需要在每次规则触发时引入插槽的新值,因为在以下示例中,我将使用此值进行连接: 我有一个将三角洲转换为恒星的电路和规则.对于每个变换产品,都是一个附加节点.对于简单网络,我将其命名为T,但是对于更复杂的网络,我最终得到的是充满T节点的网络,因为每次触发另一个增量的规则时,我都会得到一个T节点.
Is there a way to increment or change value of some variable each time rule fires? I need that for every time rule fires introduce new value of the slot, since I will use this value for connectivity in the following example: I have an electric circuit and rule that transforms delta to star. For every transform product is additional node. For simple network I have named it T, but for more complicated network I end up with network that is full of T nodes, since every time rule is triggered for another delta, I get a T node.
推荐答案
Jess具有一种特殊的变量:全局变量.它们在程序的所有部分(包括规则的RHS)中都是可见的.要创建,请使用defglobal
,例如
Jess has a special kind of variables: global variable. They are visible in all parts of a program, including the RHSs of the rules. To create, use defglobal
, e.g.
(defglobal ?*firecount* = 0)
请注意,星号是必需的.
Note that the asterisks are mandatory.
您可以像使用其他任何变量一样使用它们:
You use them just like any other variable:
(++ ?*firecount*)
(printout t "fire counter = " ?*firecount* crlf)
请注意,甚至reset
都不会清除全局变量. -有关其他详细信息,请参阅Jess手册.
Note that not even reset
clears a global. - Refer to the Jess manual for additional details.
这篇关于每次触发Jess规则时增加或更改变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!