Reputation: 2762
i have define a recursive rule but the result seems incorrect.
customer(peter,bank(maybank),customertype(personal),
citizen(malaysian),age(62),credit(50000),
income(3000),property(car) ).
isseniorcitizen(X) :- customer(X, bank(_),customertype(_),
citizen(malaysian),age(Age),credit(_),
income(_),property(_)),
Age >= 60.
lowerinterest(Senior) :- isseniorcitizen(Senior).
isseniorcitizen(peter).
But the SWI-Prolog return X = peter; X = peter.
Why it return two times rather once ?
Please help.
Thanks.
Upvotes: 0
Views: 234
Reputation: 9915
The simple problem is that you have stated that peter is a senior citizen twice; first by first order logic in your program by adding him to the "database" on top, then by simply stating that he is a senior citizen at the bottom of your program. My previous answer (add a cut) is also correct but misses the problem; it would cancel the search of a unified variable X after having found peter to be a matching atom, and would hence not progress to other X-es than peter.
Upvotes: 2