开发者

Prolog List Processing

i would like to define a list(List of Bank Customer) from predicate and process the list using some rule.

For instance, i have the customer predicate like this

customer(peter,bank(maybank),customertype(personal),
    citizen(malaysian),age(62),credit(50000),
    income(4500),property(car),bankemployee(no) ).

customer(mary,bank(maybank),customertype(vip),
    citizen(others),age(45),credit(20000),
    income(5000),property(house),bankemployee(yes) ).

I want to add them into a list programmatically inside the source code.

Then, i would like to evaluate the list whether element in the list fulfill a particular rule. Example: Whether the first item loan accept, whether the second item(customer) has lower interest.

isloanaccept(Name,Guarantor,LoanType,LoanAmount,LoanTenure) 
:-  customer(Name,bank(_),customertype(_),
    citizen(Ci),age(Age),credit(C),
    income(I),property(_),bankemployee(_)), 
    Ci == 'malaysian',
    Age >= 18,
    C > 500, 
    I > (LoanAmount / LoanTenure) / 12;
  开发者_如何学Python  isguarantor(Guarantor,Name), 
    ispersonalloan(LoanType,LoanAmount,LoanTenure);
    ishouseloan(LoanType,LoanAmount,LoanTenure);
    isbusinessloan(LoanType,LoanAmount,LoanTenure);
    iscarloan(LoanType,LoanAmount,LoanTenure).  

issenioroffer(Name,LoanAmount,LoanTenure)
:- isloanaccept(Name,LoanAmount,LoanTenure),
    isseniorcitizen(Name).

I need to program them more high level.

Please help.

Thanks.


1) To put all costomers in a list, you can use bagof (reference):

bagof(
    [Name, Bank, Type, Cit, Age, Cred, Inc, Prop, BEmp],
    customer(Name, Bank, Type, Cit, Age, Cred, Inc, Prop, BEmp),
    Customers
)

should create a list (Customers) of lists where each element contains the properties of a given customer.

I don't get question 2 :-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜