我正在prolog中编写一个程序,并且遇到了以下问题:我已经定义了谓词邻居(+,+,+,+,?),如下所示:
neighbors(X, Y, Height, Width, Neighbors):-
Xup is X-1,
Xdown is X+1,
Yleft is Y-1,
Yright is Y+1,
findall((A,B,C),(
between(Xup, Xdown, A),
between(Yleft, Yright, B),
A>=1,
B>=1),
Neighbors).
现在查询邻居(5,5,5,5,X)按预期工作,将X与其邻居列表统一,即
X = [ (4, 4, _G2809), (4, 5, _G2800), (4, 6, _G2791), (5, 4, _G2782), (5, 5, _G2773), (5, 6, _G2764), (6, 4, _G2755), (6, ..., ...), (..., ...)] .
但是,当我尝试将以下行添加到我的findall目标时出现问题:
A<=Height,
B<=Width
完整谓词看起来像这样:
neighbors(X, Y, Height, Width, Neighbors):-
Xup is X-1,
Xdown is X+1,
Yleft is Y-1,
Yright is Y+1,
findall((A,B,C),(
between(Xup, Xdown, A),
between(Yleft, Yright, B),
A>=1,
B>=1,
A<=Height,
B<=Width
),
Neighbors).
现在相同的查询,邻居(5,5,5,5,X)。导致我收到以下错误:
ERROR: Undefined procedure: neighbors/5
ERROR: However, there are definitions for:
ERROR: neighbor/2
ERROR: neighbors/2
false.
可能是什么原因?我想它与我比较这些变量的方式有关,但是由于Width和Height被实例化,我认为应该有效。感谢。
答案 0 :(得分:1)
问题在于您的比较运算符。小于或等于运算符的语法是=</2
。所以你的目标应该是:
...
A=<Height,
B=<Width
...