使用斜杠内部列表解析谓词

时间:2018-04-19 16:48:19

标签: prolog

我有以下事实:

timetable(paris, london, [10:00/11:00, 22:00/23:00])

我怎么知道某个时刻两个地方之间是否有航班?

我尝试了以下不成功:

flight_hour(Hour, [Hour/B|T]).
flight_hour(Hour, [A/B|T]) :- flight_hour(Hour, T).
flight(Place1, Place2, Hour) :- timetable(Place1, Place2, X), flight_hour(Hour, X).

斜线是什么意思?

1 个答案:

答案 0 :(得分:0)

您可以执行以下操作并指定数据结构:

timetable(paris, london, [10:00/11:00, 22:00/23:00]).

flight_hour(Hour:Min, Hour:Min/_:_).
flight_hour(Hour, [_:_/_:_,T]) :- 
    flight_hour(Hour, T).
flight(Place1, Place2, Hour):- 
    timetable(Place1, Place2, X), 
    flight_hour(Hour, X).

?- flight(paris,london,T).
T = 22:0 %i don't know if this is the result you want