Prolog date_time_stamp [closed]

吃可爱长大的小学妹 提交于 2019-12-24 19:28:07

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!