Abeer
Abeer

Reputation: 23

CLIPS missing function declaration for template

I'm trying to write a program that asks the user for the name of the person whose birthday is today to update his age but I'm getting this error (Missing function declaration for data.)

(deftemplate data 
(slot name) (slot height) (slot weight) (slot age) (multislot blood-pressure))

(deffacts s1
(data (name Anna) (height 160) (weight 56) (age 21) (blood-pressure 12 8))
(data (name Jack) (height 180) (weight 82) (age 38) (blood-pressure 19 10))
)

(deffunction ask-q (?question)
    (printout t ?question)
    (bind ?answer (read))
    ?answer
)
(defrule r1
    (not (starter-state ?))
    =>(bind ?answer (ask-q "whose birthday is today?"))
    if (lexemep ?answer)
    then ?num <-(data (name ?answer)(age ?age)))
    (modify ?fact-number (age(+ ?age 1)))
)

Upvotes: 2

Views: 802

Answers (1)

Gary Riley
Gary Riley

Reputation: 10757

The patterns come first in the rule followed by the actions. You can't place patterns within the actions of the rule. Create a separate rule to process the information created by rule r1.

         CLIPS (6.31 6/12/19)
CLIPS> 
(deftemplate data 
   (slot name)
   (slot height)
   (slot weight)
   (slot age)
   (multislot blood-pressure))
CLIPS> 
(deffacts s1
   (data (name Anna) (height 160) (weight 56) (age 21) (blood-pressure 12 8))
   (data (name Jack) (height 180) (weight 82) (age 38) (blood-pressure 19 10)))
CLIPS> 
(deffunction ask-q (?question)
   (printout t ?question " ")
   (read))
CLIPS>     
(defrule r1
   =>
   (assert (birthday (ask-q "Whose birthday is today?"))))
CLIPS> 
(defrule r2
   ?b <- (birthday ?name)
   ?num <- (data (name ?name) (age ?age))
   =>
   (retract ?b)
   (modify ?num (age (+ ?age 1))))
CLIPS> (reset)
CLIPS> (run)
Whose birthday is today? Anna
CLIPS> (facts)
f-0     (initial-fact)
f-2     (data (name Jack) (height 180) (weight 82) (age 38) (blood-pressure 19 10))
f-4     (data (name Anna) (height 160) (weight 56) (age 22) (blood-pressure 12 8))
For a total of 3 facts.
CLIPS> (reset)
CLIPS> (run)
Whose birthday is today? Jack
CLIPS> (facts)
f-0     (initial-fact)
f-1     (data (name Anna) (height 160) (weight 56) (age 21) (blood-pressure 12 8))
f-4     (data (name Jack) (height 180) (weight 82) (age 39) (blood-pressure 19 10))
For a total of 3 facts.
CLIPS> 

Upvotes: 1

Related Questions