【问题标题】:Prolog Rules Reflect StrucutreProlog 规则反映结构
【发布时间】:2010-07-19 08:11:18
【问题描述】:

我需要设计一个测试贷款是否为汽车贷款的规则。

carLoan(flexiCar,minLoanAmount(20000),maxTenure(12) ).
iscarloan(X, Y, Z) :- carLoan(X, Y >= minLoanAmount(20000), Z =<(maxTenure(12)) ).
iscarloan(X, 25000, 10).

我需要根据规则内部的事实根据结构测试 Y 和 Z 变量。

如何做到这一点?

谢谢。

【问题讨论】:

    标签: prolog structure rule


    【解决方案1】:
    iscarloan(X, Y, Z) :-
      carLoan(X, minLoanAmount(MinLoan), maxTenure(MaxTenure)),
      Y >= MinLoan,
      Z =< MaxTenure.
    

    这就是你的想法?

    【讨论】:

    • 我使用一些查询测试了规则,它显示错误指出 minLoanAmount 不是一个函数。
    • 错误信息是 ERROR: >= /2 算术 minLoanAmount 不是函数
    • 我的错 - 我修复了第二行的匹配
    【解决方案2】:
    carLoan(flexiCar, minLoanAmount(20000), maxTenure(12)).
    
    iscarloan(X, Y, Z) :-
        Y = minLoanAmount(MLA),
        Z = maxTenure(MT),
        MLAN is MLA,
        MTN is MT,
        MLAN >= 20000,
        MTN =< 12.
    
    iscarloan(X, 25000, 10).
    

    【讨论】:

    • 我得到的答案如下。 isguarantor(X,Y) :- 保证人(X,Y), notCustomer(X)。 iscarloan(LoanType, Y, Z) :- carLoan(LoanType, minLoanAmount(MLA), maxTenure(MT)), Y >= MLA, Z =
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-27
    • 2015-01-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多