tags:

views:

38

answers:

2

Hello to all, i need to write a rule which consists of sub rule.

Any idea how to achieve this ?

isloanaccept(Name, LoanAmount, LoanTenure) 
:-  customer(Name, bank(_),customertype(_),
    citizen(malaysian),age(Age),credit(C),
    income(I),property(car|house)), 
    Age >= 18,
    C > 500, 
    I > (LoanAmount / LoanTenure) / 12.
lowerinterest(Senior) :- isseniorcitizen(Senior).

For instance, i need to check the customer type . If customer type is VIP, interest lower. If age is above 60, interest lower.

Please help.

Thanks.

A: 

That's what I would do:

% usage: isInterestOk(+CustomerType, +Interest)
isInterestOk('VIP', Interest) :-
    Interest =< 1000.
isInterestOk('normal', Interest) :-
    Interest =< 500.
Roland Illig
Let me rephrase my question. I need to create a function which evaluate the loan and if the loan is accept then i need to check if it got lower interest offer to the person.
peterwkc
A: 

Adding an extra argument to isloanaccept is probably the easiest way.

isloanaccept(Name, LoanAmount, LoanTenure, Interest) :-
    customer(Name, bank(_), customertype(Type), citizen(malaysian), age(Age),
             credit(C), income(I), property(car|house)), 
    Age >= 18,
    C > 500,
    I > (LoanAmount / LoanTenure) / 12,
    interest(Age, Interest).

% Interest depending on age and customertype; add parameters, or pass in a list,
% to have interest determined by other factors
interest(Age,Type,Interest) :-
    (senior_citizen(Age) ->
        Interest = 0.05
    ; Type = vip ->
        Interest = 0.07
    ;
        Interest = 0.10
    ).

PS.: Please try to format Prolog code this way, that makes it a lot easier to read.

larsmans