我需要编写一个由子规则组成的规则。
知道怎么做到这一点?
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岁,则降低利息。
请帮忙。
感谢。
答案 0 :(得分: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代码,这样可以更容易阅读。
答案 1 :(得分:0)
这就是我要做的事情:
% usage: isInterestOk(+CustomerType, +Interest)
isInterestOk('VIP', Interest) :-
Interest =< 1000.
isInterestOk('normal', Interest) :-
Interest =< 500.