(defrule ask-question-1
=>
(printout t "Do you have a full-time job or go to school full-time? (yes/no): ")
(assert (full-time-occupation (read)))
)
(defrule ask-question-2
=>
(printout t "Do you have a driver's license? (yes/no): ")
(assert (has-drivers-license (read)))
)
(defrule determine-age
(and (full-time-occupation yes) (has-drivers-license yes))
=>
(printout t "You are likely an adult." crlf)
)
(defrule determine-age
(and (full-time-occupation no) (has-drivers-license no))
=>
(printout t "You are likely a teen." crlf)
)
(defrule determine-age
(and (full-time-occupation no) (has-drivers-license yes))
=>
(printout t "You are likely a teen." crlf)
)
(defrule determine-age
(and (full-time-occupation yes) (has-drivers-license no))
=>
(printout t "You are likely an adult." crlf)
)
When I run the above code and answer "no" to both questions, I don't get any output. I was expecting the program to print out: "You are likely a teen.". What is the issue? I use CLIPS 6.4.1.
You've used the same name for four of your rules, so you can fix the issue by giving them different names. If you watch compilations when you load your rules, you'll get warning messages when rules are redefined.
CLIPS> (watch compilations)
CLIPS> (load rules.clp)
Defining defrule: ask-question-1 +j+j
Defining defrule: ask-question-2 +j
Defining defrule: determine-age +j+j+j
[CSTRCPSR1] rules.clp, Line 20, WARNING: Redefining defrule: determine-age +j+j+j
[CSTRCPSR1] rules.clp, Line 26, WARNING: Redefining defrule: determine-age +j+j+j
[CSTRCPSR1] rules.clp, Line 32, WARNING: Redefining defrule: determine-age +j+j+j
TRUE
CLIPS>