如果给定的版本具有给定的顺序关系,则写一个谓词 complst/3 为真。顺序将是:lt、le、gt、ge 或 eq 之一(小于、小于或等于、大于、大于或等于、等于),并且谓词应该为所有适用的关系。例如,
?- complst([2,3,4], [2,3,5], C).
C = lt ;
C = le .
?- complst([1,2,3,4], [1,1,8], C).
C = gt ;
C = ge .
为了达到目的,我写了一个谓词:
complst([], [], Cmp) :-
Cmp = eq, !.
complst([A], [B], Cmp) :-
A > B,
Cmp = gt.
complst([A], [B], Cmp):-
A < B,
Cmp = lt.
complst([A], [B], Cmp):-
A >= B,
Cmp = ge.
complst([A], [B], Cmp):-
A =< B,
Cmp = le.
complst([], [B], Cmp):-
Cmp = le, !.
complst([], [B], Cmp):-
Cmp = lt, !.
complst([A], [], Cmp):-
Cmp = ge, !.
complst([A], [], Cmp):-
Cmp = gt, !.
complst([X|XS], [Y|YS], Cmp):-
X > Y,
cmp_list([X], [Y], Cmp).
complst([X|XS], [Y|YS], Cmp):-
X < Y,
cmp_list([X], [Y], Cmp).
complst([X|XS], [Y|YS], Cmp):-
X == Y,
cmp_list(XS, YS, Cmp).
但问题是,除非我按回车,否则输出永远不会停止。任何人都可以帮我解决这个问题吗?提前致谢!!