开发者

Prolog Rule - need help with getting something working?

I want to write a rule in prolog, which basically says If a user X has not paid amount Y within 7 days then it will evaluate to payment_outstanding(X).

so far i have something like this:

debtpayment_unfulfilled(X) :- owes_money(X, Amountowed, Amountpaid, Days), Days > 7 ,Amountowed > Amountpaid.

owes_money(bob, 500, 0, 3).      开发者_JAVA百科      //bob borrowed 500 on day 3

the rule works, but the problem is the Days + 7 part, for example in the system if someone borrowed on day 3 then the clause will never evaluate to true has Days will always be 3, how can i implement this? do i have to write a seperate rule?? hope you understand what im trying to say.

thanks


If I've got you correctly, this is not possible. You should implement in your rule owes_money(bob, 500, 0, 3). exact date when bob take the money and then compare it to today's date.

For getting the exact date take a look at this predicate: get_time(-Time). And also for dealing with time you can use:

convert_time(+Time, -String)
convert_time(+Time, -Year, -Month, -Day, -Hour, -Minute, -Second, -MilliSeconds)

I'm still not sure this is not a homework and I'm a little afraid to give you the solution out of the box.

A fast solution would be to change your predicate owes_money like this:

owes_money(bob, 500, 0, 2010, 3, 10). %2010 for the year, 3 for the month  ... 

Then compare this date with the current date:

get_time(X), convert_time(X, CurrYear, CurrMonth, CurrDay, _, _, _, _).%CurrYear will give you current year, etc ... . You don't need the hour minutes etc .. that's why are the _

Now what is left is to compare CurrYear, CurrMonth and CurrDay with what you get from the owes_money predicate and see how many days have passed.

Hope this is helpful!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜