2010-07-21 120 views
1

我需要編寫一個由子規則組成的規則。Prolog組合規則

任何想法如何實現這一目標?

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). 

例如,我需要檢查客戶類型。 如果客戶類型是VIP,則利息較低。 如果年齡在60歲以上,則利息較低。

請幫忙。

謝謝。

回答

1

增加一個額外的參數isloanaccept可能是最簡單的方法。

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:請嘗試用這種方式來格式化Prolog代碼,這使得它更容易閱讀。

0

這就是我會做:

% usage: isInterestOk(+CustomerType, +Interest) 
isInterestOk('VIP', Interest) :- 
    Interest =< 1000. 
isInterestOk('normal', Interest) :- 
    Interest =< 500. 
+0

讓我來重述一下我的問題。我需要創建一個評估貸款的函數,如果貸款是可以接受的,那麼我需要檢查它是否有較低的利息提供給這個人。 – peterwkc 2010-07-21 07:21:28