tags:

views:

68

answers:

1

Hello people..

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).            //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

+1  A: 

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!

anthares
I'll have a play with what you've given me. I'm actually researching obligation management, if you look at some of my other questions you will see that I often don't just "ask" someone to do something for me. I have extremely limited knowledge of prolog and am trying my best, like i said before it's not homework! - i havent had any "homework" in years to be honest! Thanks for the reply mate
KP65
Fair enough then ... I will help you further if you need.
anthares