Nadine Salem
Nadine Salem

Reputation: 31

clips [EXPRNPSR3] Missing function declaration for person

; template person

(deftemplate person
(slot name (type STRING))
(slot gender (type SYMBOL)(allowed-symbols m f)); male, female
(slot birthyear (type INTEGER))
(slot birthPlace(type STRING))
(slot Fname (type STRING))
(slot Mname (type STRING))
(multislot siblingsName (type STRING))
(slot spouse (type STRING))
(slot height (type INTEGER))
(slot weight (type INTEGER))
(slot hairColor (type STRING))
(slot eyeColor (type STRING))
(multislot oddHabits (type STRING))
)

; menu

(defrule menu
 (declare (salience 9000))
 (initial-fact) 
=>
(printout t crlf 
    "Menu : " crlf
    " 1-    Infer family relations " crlf
    " 2-    Add additional members " crlf
    " 3-    Modify properties of already existing members " crlf
    " 4-    List properties of a specific individual by name or reference. " crlf
    " 5-    Find for all individuals matching a certain property. " crlf
    " 6-    Find all individuals matching two properties. " crlf
    " 7-    Display family relations (same like 1) along with their height comparison." crlf
    " 8-    exit the program" crlf 
    "Choose 1 - 8 -> "
)
(assert (task type =(read)))
)

; exit

(defrule Exit
(task type 8)
=>
(exit)
)




(defrule  AddMember
(task type 2)
=>
(printout t "Enter Name" crlf)
(bind ?name (read))
(printout t "Enter gender" crlf)
(bind ?G (read))
(printout t "Enter birth year" crlf)
(bind ?BY(read))
(printout t "Enter birth place" crlf)
(bind ?BP(read))
(printout t "Enter Father name " crlf)
(bind ?FN (read))
(printout t "Enter Mother name" crlf)
(bind ?MN(read))
(printout t "Enter siblings" crlf)
(bind ?SI(readline))
(printout t "Enter spouse" crlf)
(bind ?SP (read))
(printout t "Enter height" crlf)
(bind ?H (read))
(assert 
(person
(name ?name)(gender ?G)(birthyear ?BY)(birthPlace ?BP)(Fname ?FN)(Mname ?MN)(siblingsName ?SI )(spouse ?SP) (height ?H))
)
)


(defrule Modify
(task type 3)
=>

(printout t " (a) to modify gender" crlf)
(printout t " (b) to modify Birth Year" crlf)
(printout t " (c) to modify Birth Place" crlf)
(printout t " (d) to modify Father Name" crlf)
(printout t " (e) to modify Mother Name" crlf)
(printout t " (f) to modify Spouse" crlf)
(printout t " (g) to modify height" crlf)
(printout t " (h) to modify weight" crlf)
(assert (task type =(read)))
)


(defrule ModifyGender 
(task type a)
=>
(printout t "Enter the name of person that you want to modify" crlf)
(bind ?n (read))
(printout t " Enter new value" crlf)
(bind ?V (read))
?num <- (person (name ?n))
(printout t " num is " ?num " " crlf)

(modify ?num (gender ?V))
)

When loading the file of my project an error shows up:

[EXPRNPSR3] Missing function declaration for person.

Error:

(defrule MAIN::ModifyGender
(task type a)
=>
(printout t "Enter the name of person that you want to modify" crlf)
(bind ?n (read))
(printout t " Enter new value" crlf)
(bind ?V (read))
?num
<-

Can anyone help me?

Upvotes: 3

Views: 8361

Answers (1)

Gary Riley
Gary Riley

Reputation: 10757

Patterns matching facts are only allowed in the condition portion of a rule, not in the actions of the rule. You can either use multiple rules to determine which person to change and to apply the change:

(defrule ModifyGender-ask 
   ?f <- (task type a)
   =>
   (retract ?f)
   (printout t "Enter the name of person that you want to modify" crlf)
   (bind ?n (read))
   (printout t " Enter new value" crlf)
   (bind ?V (read))
   (assert (modify-gender ?n ?V)))

(defrule ModifyGender-apply 
   ?f <- (modify-gender ?n ?v)
   ?num <- (person (name ?n))
   =>
   (retract ?f)
   (modify ?num (gender ?v)))

(defrule ModifyGender-don't-apply 
   ?f <- (modify-gender ?n ?v)
   (not (person (name ?n)))
   =>
   (retract ?f))

Or you can use the fact-set query functions to locate and change the person from the actions of the rule:

(defrule ModifyGender 
   ?f <- (task type a)
   =>
   (retract ?f)
   (printout t "Enter the name of person that you want to modify" crlf)
   (bind ?n (read))
   (printout t " Enter new value" crlf)
   (bind ?V (read))
   (if (any-factp ((?p person)) (eq ?p:name ?n))
      then
      (do-for-fact ((?p person)) (eq ?p:name ?n)
         (modify ?p (gender ?V)))
      else
      (printout t "Person " ?n " does not exist." crlf)))

Upvotes: 2

Related Questions