Reputation: 1
I have tried to vary the facts using lists and a cycle for but I have not succeeded, The way I tried it is to create a list for each variable in the template and then apply an cycle for but it didn't work. The example python code in which I have tried it is:
import clips
DEFTEMPLATE_DORMITORIO = """
(deftemplate Dormitorio
(slot Presencia (type SYMBOL))
(slot Iluminación (type SYMBOL)))
"""
DEFTEMPLATE_SALADEESTAR = """
(deftemplate SalaDeEstar
(slot Presencia (type SYMBOL))
(slot Iluminación (type SYMBOL)))
"""
DEFTEMPLATE_GENERALES = """
(deftemplate Generales
(slot Hora (type INTEGER)))
"""
env = clips.Environment()
env.build(DEFTEMPLATE_DORMITORIO)
env.build(DEFTEMPLATE_SALADEESTAR)
env.build(DEFTEMPLATE_GENERALES)
env.load('reglas2.CLP')
Dormitorio = env.find_template('Dormitorio')
fact_Dormitorio = Dormitorio.assert_fact(Presencia = clips.Symbol('Si'),
Iluminación = clips.Symbol('OFF'))
SalaDeEstar = env.find_template('SalaDeEstar')
fact_SalaDeEstar = SalaDeEstar.assert_fact(Presencia = clips.Symbol('Si'),
Iluminación = clips.Symbol('OFF'))
Generales = env.find_template('Generales')
fact_Generales = Generales.assert_fact(Hora = 2100)
env.run()
for facts in env.facts():
print(facts)
Upvotes: -1
Views: 136
Reputation: 15060
You need to declare a multislot
for that.
import clips
DEFTEMPLATE_DORMITORIO = """
(deftemplate Dormitorio
(multislot Presencia (type SYMBOL))
(slot Iluminacion (type SYMBOL)))
"""
environment = clips.Environment()
environment.build(DEFTEMPLATE_DORMITORIO)
template = environment.find_template("Dormitorio")
fact = template.assert_fact(Presencia=[clips.Symbol('Si'),
clips.Symbol('No')],
Iluminacion=clips.Symbol('OFF'))
for element in fact['Presencia']:
print(element)
Upvotes: 0