Increment or change variable each time Jess rule fires

北城以北 提交于 2019-12-13 03:32:06

问题


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.


回答1:


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)

Note that not even reset clears a global. - Refer to the Jess manual for additional details.



来源:https://stackoverflow.com/questions/47584478/increment-or-change-variable-each-time-jess-rule-fires

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!