Prolog ERROR: Undefined procedure, <= involved
Prolog ERROR: Undefined procedure, <= involved
我正在编写 prolog 中的程序,遇到以下问题:我定义了谓词 neighbors(+,+,+,+,?) 如下:
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).
现在查询 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).
现在相同的查询,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 是实例化的,我认为这应该有效。谢谢。
问题出在你的比较运算符上。小于或等于运算符的语法是 =</2
。所以你的目标应该是:
...
A=<Height,
B=<Width
...
我正在编写 prolog 中的程序,遇到以下问题:我定义了谓词 neighbors(+,+,+,+,?) 如下:
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).
现在查询 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).
现在相同的查询,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 是实例化的,我认为这应该有效。谢谢。
问题出在你的比较运算符上。小于或等于运算符的语法是 =</2
。所以你的目标应该是:
...
A=<Height,
B=<Width
...