问题
Trying to make a rule within prolog, which would ask if any messages where sent between 2 individuals (where both individuals can be the recipient or the sender of the message) before a given date. After calling whether it is true or not, it is to print all the logs where the 2 users have exchanged messages before the given time.
so far i thought,
msgbefore(X,Y,D) :-
message(X,Y,D1),
date_time_stamp(D),
date_time_stamp(D1),
D1 < D,
message(Y,X,D1),
date_time_stamp(D),
date_time_stamp(D1),
D1 < D.
database consists of:
message(sonny,robert,'2012-05-12').
message(robert,sarah,'2012-05-12').
message(julie,mary,'2012-05-12').
message(fred,nayna,'2012-05-13').
message(fred,daniel,'2012-05-14').
message(nayna,lucia,'2012-05-15').
please help,
回答1:
Just an hint: date_time_stamp requires 2 arguments and is rather difficult to use, but since your dates are provided as atoms in standard form, you can directly compare them. For instance
1 ?- message(A,B,Date),Date @< '2012-05-13'.
A = sonny,
B = robert,
Date = '2012-05-12' ;
...
来源:https://stackoverflow.com/questions/20895795/prolog-date-time-stamp