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
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: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_moneylike this:Then compare this date with the current date:
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!