if statement - CLIPS - if then else function gives [CSTRCPSR1] err -
here error summary:
clips> (load "c:/users/labor/desktop/witek/projekt.clp") defining defrule: r1 +j+j defining defrule: r2 +j+j defining defrule: r3 =j+j+j defining defrule: imie-if =j=j+j+j [cstrcpsr1] expected beginning of construct.
and here code clips program. want react different if name , last name different abraham lincoln.
(defrule r1 (initial-fact) => (printout t "enter name:" crlf) (bind ?name (read)) (assert (name ?name))) (defrule r2 (name ?name) => (printout t "enter last name" crlf) (bind ?lastnm (read)) (assert (lastnm ?lastnm))) (defrule r3 (and(name ?name)(lastnm ?lastnm)) => (printout t "how old " ?name "?" crlf) (bind ?age (read)) (assert (age ?age))) (defrule name-if (name ?name)(lastnm ?lastnm)(age ?age) => (if(and(eq ?name abraham)(eq ?lastnm lincoln)) (printout t "hello " ?name " " ?lastnm ", " ?age " years old bro" crlf)) else (printout t "hello " ?name " " ?lastnm ", " ?age " years old" crlf)))
i copied if statement logic webpage , not quite sure what, in case, 'eq' stands for... i'd appreciate if additionally explain role of it.
regards, w
you have right parenthesis @ end of clause causing issue. mac os , window clips ides have balance command can use see if parentheses balanced within construct. click inside construct , apply balance command several times until entire construct selected. if place cursor keyword , balance, you'll see if statement closed parenthesis @ end of clause , else clause left dangling.
the corrected rule is:
(defrule name-if (name ?name) (lastnm ?lastnm) (age ?age) => (if (and (eq ?name abraham) (eq ?lastnm lincoln)) (printout t "hello" ?name " " ?lastnm ", " ?age " years old bro" crlf) else (printout t "hello " ?name " " ?lastnm ", " ?age " years old" crlf)))
the eq predicate short equals. unlike = predicate expects numeric arguments, eq compares values of type.
Comments
Post a Comment