List Prolog列表处理

List Prolog列表处理,list,prolog,List,Prolog,我想从谓词定义一个列表(银行客户列表),并使用一些规则处理该列表 例如,我有这样的customer谓词 customer(peter,bank(maybank),customertype(personal), citizen(malaysian),age(62),credit(50000), income(4500),property(car),bankemployee(no) ). customer(mary,bank(maybank),customertype(vip),

我想从谓词定义一个列表(银行客户列表),并使用一些规则处理该列表

例如,我有这样的customer谓词

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) ).
我想在源代码中以编程方式将它们添加到列表中

然后,我想评估列表中的元素是否满足特定规则。示例:第一项贷款是否接受,第二项(客户)是否有较低的利息

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).
我需要对他们进行更高层次的编程

请帮忙

谢谢

1)要将所有客户放在一个列表中,您可以使用
bagof
():

应创建列表(
客户
),其中每个元素包含给定客户的属性

我没有问题2:-)

1)要将所有客户放入一个列表中,您可以使用
bagof
():

应创建列表(
客户
),其中每个元素包含给定客户的属性


我不明白问题2:-)

有这么多参数,把它们放在一个函子(记录)中是值得的,比如说,
cust(Name,Bank,…,BEmp)
所以你可以说
bagof(Customer,Customer(Customer),Customers)
。有这么多参数,把它们放在函子(记录)中是值得的,比如说,
cust(姓名,银行,…,BEmp)
所以你可以说
bagof(客户,客户(客户),客户)
bagof(
    [Name, Bank, Type, Cit, Age, Cred, Inc, Prop, BEmp],
    customer(Name, Bank, Type, Cit, Age, Cred, Inc, Prop, BEmp),
    Customers
)