Reputation: 67
I'm trying to create an expert system that decides whether or not you can buy a house. I want to know how to word a rule that allows the person to buy a house if they're over a certain age. For Example, if you type in that you're over 40 years old the system would come back and tell you that you're not allowed to buy a home. I have tried this code below but it doesn't work
(defrule age-over-forty
(student yes)
(income low)
(credit excellent)
(age 40>)
=>
(printout t "You can not buy a house" crlf))
EDIT: What I mean by "it doesn't work" ; When I run it, you type in a age, lets just say I typed in 46. It would add it to the facts but it is supposed to print out "You can not buy a house" so it doesn't satisfy the (age 40>) part of the code.
Upvotes: 1
Views: 826
Reputation: 10757
Use the predicate constraint (section 5.4.1.5 of the CLIPS 6.3 Basic Programming Guide) or alternatively the test conditional element to perform a numeric comparison.
CLIPS (6.31 6/12/19)
CLIPS>
(defrule age-over-forty
(student yes)
(income low)
(credit excellent)
(age ?age&:(> ?age 40))
=>
(printout t "You can not buy a house" crlf))
CLIPS>
(assert (student yes)
(income low)
(credit excellent)
(age 46))
<Fact-4>
CLIPS> (agenda)
0 age-over-forty: f-1,f-2,f-3,f-4
For a total of 1 activation.
CLIPS> (run)
You can not buy a house
CLIPS>
Upvotes: 1