Iván
Iván

Reputation: 1

Issue running a simple CLIPS program

(deffacts hechos-iniciales
(tiene-pelos)
(tiene-pezugnas)
(tiene-rayas-negras))

(defrule mamifero-1
(tiene-pelos)
=>
(assert (es-mamifero)))

(defrule mamifero-2
(da-leche)
=>
(assert (es-mamifero)))

(defrule ungulado-1
(es-mamifero)
(tiene-pezugnas)
=>
(assert (es-ungulado)))

(defrule ungulado-2
(es-mamifero)
(rumia)
=>
(assert (es-ungulado)))

(defrule jirafa
(es-ungulado)
(tiene-cuello-largo)
=>
(printout t "Es una jirafa" crlf))
 
(defrule cebra
(es-ungulado)
(tiene-rayas-negras)
=>
(printout t "Es una cebra" crlf))

I got this code and I load from a file using (load file.clp) and then I executed (run) and nothing is shown, I expect that some printout pop up but this neves happen.
Im new in CLIPS im sure that the solution will be a detail that im missing. I apreciate the help.

I tried to apply this facts to print if is a zebra or a girafe but I never get a response.

Upvotes: 0

Views: 28

Answers (1)

Gary Riley
Gary Riley

Reputation: 10757

The most likely explanation is that you didn't issue a (reset) command before the (run) command. The (reset) command is necessary to assert the facts in the hechos-iniciales deffacts.

         CLIPS (6.4.1 4/8/23)
CLIPS> 
(deffacts hechos-iniciales
   (tiene-pelos)
   (tiene-pezugnas)
   (tiene-rayas-negras))
CLIPS> 
(defrule mamifero-1
   (tiene-pelos)
   =>
   (assert (es-mamifero)))
CLIPS> 
(defrule mamifero-2
   (da-leche)
   =>
   (assert (es-mamifero)))
CLIPS> 
(defrule ungulado-1
   (es-mamifero)
   (tiene-pezugnas)
   =>
   (assert (es-ungulado)))
CLIPS> 
(defrule ungulado-2
   (es-mamifero)
   (rumia)
   =>
   (assert (es-ungulado)))
CLIPS> 
(defrule jirafa
   (es-ungulado)
   (tiene-cuello-largo)
   =>
   (printout t "Es una jirafa" crlf))
CLIPS>  
(defrule cebra
   (es-ungulado)
   (tiene-rayas-negras)
   =>
   (printout t "Es una cebra" crlf))
CLIPS> (reset)
CLIPS> (run)
Es una cebra
CLIPS> (facts)
f-1     (tiene-pelos)
f-2     (tiene-pezugnas)
f-3     (tiene-rayas-negras)
f-4     (es-mamifero)
f-5     (es-ungulado)
For a total of 5 facts.
CLIPS> 

Upvotes: 0

Related Questions