我写这个程序给我这个结果:“X=john”“Y=jane”
likes(john,mary).
likes(mary,jane).
likes(l,k).
likes(X,Y) :- likes(X,Z), likes(Z,Y).
但是如果运行这个程序这样结果:我认为程序进入循环!我想在真实答案后停下来!
1 ?- likes(X,Y).
X = john,
Y = mary ;
X = mary,
Y = jane ;
X = l,
Y = k ;
X = john,
Y = jane ;
ERROR: Out of local stack
我有错误!如何解决这个问题?
通过调试:
[debug] 3 ?- likes(john,Y).
T Call: (6) likes(john, _G2162)
T Exit: (6) likes(john, mary)
Y = mary ;
T Redo: (6) likes(john, _G2162)
T Call: (7) likes(john, _G2267)
T Exit: (7) likes(john, mary)
T Call: (7) likes(mary, _G2162)
T Exit: (7) likes(mary, jane)
T Exit: (6) likes(john, jane)
Y = jane ;
T Redo: (7) likes(mary, _G2162)
T Call: (8) likes(mary, _G2267)
T Exit: (8) likes(mary, jane)
T Call: (8) likes(jane, _G2162)
T Call: (9) likes(jane, _G2267)
T Call: (10) likes(jane, _G2267)
T Call: (11) likes(jane, _G2267)
T Call: (12) likes(jane, _G2267)
T Call: (13) likes(jane, _G2267)
T Call: (14) likes(jane, _G2267)
T Call: (15) likes(jane, _G2267)
等等..为什么喜欢(简,_G2267)??????