Prolog date_time_stamp [英] Prolog date_time_stamp

查看:36
本文介绍了Prolog date_time_stamp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试在 prolog 中制定规则,该规则将询问在给定日期之前是否有任何消息在 2 个人之间发送(其中两个人都可以是消息的接收者或发送者).调用是否为true后,打印2个用户在给定时间之前交换过的所有日志.

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.

到目前为止我认为,

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.

数据库包括:

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

请帮忙,

推荐答案

只是一个提示:date_time_stamp 需要 2 个参数,使用起来相当困难,但由于您的日期以标准形式作为原子提供,您可以直接比较它们.例如

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' ;
...

这篇关于Prolog date_time_stamp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆