Question

I'm new to CLIPS expert system.

How do I tell CLIPS to stop executing rules after performing a specific instruction ????!!

Somethin' like this :

(defrule  firstRule   
   (some assumption) 
   => 
   (if (X happened) then (and (print "yikes 1")(terminate the program))

(defrule  secondRule 
   (some assumption) 
   => 
   (if (Y happened) then (and (print "yikes 2")(terminate the program))

(defrule  thirdRule 
   (some assumption) 
   => 
   (if (Z happened) then (and (print "yikes 3")(terminate the program))

In case of Y and Z happening and X not, I want something like this to be printed out :

yikes 2
Was it helpful?

Solution

Use this:

(if [condition]
   then
   (printout t "yikes 3" crlf)
   (halt))

Where [condition] would be something like a variable, ?b, or an expression, (> 3 4). In the printout statement, t is the logical name which indicates where the output should be directed (in this case t indicates standard output) and crlf prints a carriage return/line feed (new line for the output). The (halt) statement halts execution of the rules after the current rule has finished executing. You could then restart execution by entering (run) at the command prompt. Alternately, the (exit) command will immediately terminate execution of the rule as well as CLIPS.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top