Quiero escribir una regla que diga lo siguiente
if x > y => assert x
dónde x
y y
Son variables y sus valores se dan como hechos.
¿Cómo lo hago?
Respuestas
2 para la respuesta № 1Si x ya existe como un hecho, entonces afirmarlouna vez más, las acciones de la regla serían innecesarias, pero si desea afirmar un hecho que indica que x es mayor que y, entonces podría hacerlo de la siguiente manera:
CLIPS>
(defrule greater-than
(x ?x)
(y ?y)
(test (> ?x ?y))
=>
(assert (x-is-greater-than-y)))
CLIPS> (assert (x 4))
<Fact-1>
CLIPS> (assert (y 1))
<Fact-2>
CLIPS> (agenda)
0 greater-than: f-1,f-2
For a total of 1 activation.
CLIPS> (run)
CLIPS> (facts)
f-0 (initial-fact)
f-1 (x 4)
f-2 (y 1)
f-3 (x-is-greater-than-y)
For a total of 4 facts.
CLIPS>