Say I have a structure time
with the format time(hour, minute)
. How would I go about writing a rule to compare them? Something along the lines of compareTime(time1,time2) that returns yes if time1 is strictly before time2.
I am just starting out with Prolog after years of working with C, and the entire language is very very confusing to me.
The standard compare/3
predicate already does what you want:
?- compare(O, time(1,1), time(1,1)).
O = (=).
?- compare(O, time(1,1), time(1,2)).
O = (<).
?- compare(O, time(1,3), time(1,2)).
O = (>).
?- compare(O, time(1,3), time(2,2)).
O = (<).
?- compare(O, time(3,2), time(2,2)).
O = (>).
so...
earlier(T1, T2) :- compare((<), T1, T2).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With