我想添加一个自动计数器作为属性实际上使用clipspy它意味着第一个事实,你断言计数为1,第二个为2,依此类推。因为我是剪辑,规则和事实编码的初学者,我不知道如何添加这一点。如果有人能帮我解决这个问题,我要提前感谢你。以下是我的代码:
import clips
template_string = """
(deftemplate person
(slot name (type STRING))
(slot surname (type STRING)))
"""
Dict = {'name': 'John', 'surname': 'Doe' }
env = clips.Environment()
env.build(template_string)
template = env.find_template('person')
fact = template.assert_fact(**Dict)
assert_fact = fact
env.run()
for fact in env.facts():
print(fact)发布于 2021-09-27 12:38:49
事实对象已经具有指示其断言位置的indexes。
索引从1开始。
print(fact.index)如果想要向事实本身添加增量计数器,可以使用插槽的defglobal、deffunction和default-dynamic属性来实现。
(defglobal ?*counter* = 0)
(deffunction increase ()
(bind ?*counter* (+ ?*counter* 1)))
(deftemplate person
(slot name (type STRING))
(slot surname (type STRING))
(slot counter (type INTEGER) (default-dynamic (increase))))
(assert (person (name "John") (surname "Doe")))https://stackoverflow.com/questions/69345854
复制相似问题