Dec
Dec

Reputation: 1

CLIPS 6.3 IF Statement

I am working on a project and would like to find out why my if statement isn't working. My code is the following:

(defrule accept-location-lessthan-path
(or (geological-survey-lessthan-path-is stable) (geological-survey-lessthan-path-is Stable))
=>
(if (production-is medium)
then
(assert (medium-outcome))
(printout t "Second best "crlf)
else
(if (production-is high)
(assert (ideal-location))
(printout t "
Accepted! The location is ideal; you can start building now! :) " crlf))))

The error it gives me is (Missing function declaration for production-is). Could someone advice me on what the problem is. Thank you.

Upvotes: 0

Views: 454

Answers (1)

Gary Riley
Gary Riley

Reputation: 10757

Perhaps you're expecting the if function to do pattern-matching to determine if the fact (production-is medium) or (production-is high) exists. That won't work because the if function is similar to other languages such as Java and C where the function expects an expression to evaluate (such as a function call or a variable). In your if statements, the expressions (production-is medium) and (production-is high) are function calls and since you don't have a production-is function declared, you get an error message.

You should split your original rule into two rules:

(defrule accept-location-lessthan-path-medium
   (geological-survey-lessthan-path-is stable | Stable)
   (production-is medium)
   =>
   (assert (medium-outcome))
   (printout t "Second best" crlf))


(defrule accept-location-lessthan-path-high
   (geological-survey-lessthan-path-is stable | Stable)
   (production-is high)
   =>
   (assert (ideal-location))
   (printout t "Accepted! The location is ideal; you can start building now! :)" crlf))

Upvotes: 1

Related Questions