I don't see the bug in the syntax of the program, the error I get is this:
Reglas.CLP, Line 6: Syntax Error: Check appropriate syntax for defrule. ERROR: (defrule MAIN::DormitorioIluminación_Encender ?d <- (Dormitorio (Presencia Si) (Iluminación Apagada)) ?o <- (Otras (
Python code:
import clips
DEFTEMPLATE_STRING = """
(deftemplate Dormitorio
(slot Presencia (type SYMBOL))
(slot Iluminación (type SYMBOL)))
"""
"""
(deftemplate Otras
(slot Hora (type INTEGER))
(slot Estación (type SYMBOL)))
"""
env = clips.Environment()
env.build(DEFTEMPLATE_STRING)
env.load('Reglas.CLP')
Dormitorio = env.find_template('Dormitorio')
fact_Dormitorio = Dormitorio.assert_fact(Presencia = clips.Symbol('Si'),
Iluminación = clips.Symbol('Apagada'))
Otras = env.find_template('Otras')
fact_Otras = Otras.assert_fact(Hora = '2000',
Estación = clips.Symbol('Verano'))
env.run()
CLIPS code:
(defrule Regla1
?d <- (Dormitorio
(Presencia Si)
(Iluminación Apagada))
?o <- (Otras
(Hora ?Hora))
(test (and (>= ?Hora 1800) (< ?Hora 2300)))
=>
(printout t "Encender la iluminación del dormitorio." crlf)
(modify ?d (Iluminación Encendida))
)
What is the error?
mkrieger1
24.2k7 gold badges68 silver badges84 bronze badges
1 Answer 1
You can't place multiple constructs in your call in the string you pass to the build method. The deftemplate Dormitorio is getting defined but not Otras.
answered Dec 30, 2022 at 7:14
Gary Riley
10.8k2 gold badges22 silver badges37 bronze badges
Sign up to request clarification or add additional context in comments.
3 Comments
FernandoRT
now when I define Otras with the build I don't get this error, but now it says: in assert_fact raise PUT_SLOT_ERROR[ret](slot) TypeError: invalid type for slot 'Hora'
Gary Riley
I'm not familiar with Python syntax, but my guess would be that you need to use 2000 in place of '2000'.
FernandoRT
Yes, that was the error, thank you