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.

enter image description here

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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -