您的代码很奇怪,但是我可以建议您使用跟踪谓词进行测试。这是示例:
4 ?- trace([equals,contains]).
% equals/2: [call, redo, exit, fail]
% contains/2: [call, redo, exit, fail]
true.
[debug] 5 ?- equals([1,2,3],[1,2,1,3]).
T Call: (7) equals([1, 2, 3], [1, 2, 1, 3])
T Call: (8) equals([2, 3], [2, 1, 3])
T Call: (9) equals([3], [1, 3])
T Call: (10) contains([3], [1, 3])
T Fail: (10) contains([3], [1, 3])
T Fail: (9) equals([3], [1, 3])
T Redo: (8) equals([2, 3], [2, 1, 3])
T Call: (9) contains([2, 3], [2, 1, 3])
T Call: (10) contains([2, 3], [1, 3])
T Fail: (10) contains([2, 3], [1, 3])
T Fail: (9) contains([2, 3], [2, 1, 3])
T Fail: (8) equals([2, 3], [2, 1, 3])
T Redo: (7) equals([1, 2, 3], [1, 2, 1, 3])
T Call: (8) contains([1, 2, 3], [1, 2, 1, 3])
T Call: (9) contains([1, 2, 3], [2, 1, 3])
T Call: (10) contains([1, 2, 3], [1, 3])
T Call: (11) contains([1, 2, 3], [3])
T Call: (12) contains([1, 2, 3], [])
T Exit: (12) contains([1, 2, 3], [])
T Exit: (11) contains([1, 2, 3], [3])
T Exit: (10) contains([1, 2, 3], [1, 3])
T Exit: (9) contains([1, 2, 3], [2, 1, 3])
T Exit: (8) contains([1, 2, 3], [1, 2, 1, 3])
T Call: (8) contains([1, 2, 1, 3], [1, 2, 3])
T Call: (9) contains([1, 2, 1, 3], [2, 3])
T Call: (10) contains([1, 2, 1, 3], [3])
T Call: (11) contains([1, 2, 1, 3], [])
T Exit: (11) contains([1, 2, 1, 3], [])
T Exit: (10) contains([1, 2, 1, 3], [3])
T Exit: (9) contains([1, 2, 1, 3], [2, 3])
T Exit: (8) contains([1, 2, 1, 3], [1, 2, 3])
T Exit: (7) equals([1, 2, 3], [1, 2, 1, 3])
true