tags:

views:

44

answers:

1

Hello to all, 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;
    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  A: 

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

Mau
Thanks. Problem solved.
peterwkc
And with so many arguments, it becomes worthwhile to put them in a functor (record), say, `cust(Name, Bank, ..., BEmp)` so you can say `bagof(Customer, customer(Customer), Customers)`.
larsmans
Definitely! I agree.
Mau