tags:

views:

32

answers:

1

Hello to all, 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.

+2  A: 

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.

Henrik
I did not specify peter is a senior citizen twice. isseniorcitizen(peter). This is a query. How to solve it ? Thanks.
peterwkc
By putting it in the file, it becomes a fact. Queries are entered at the prompt.
larsmans
Thanks for your explanation.
peterwkc