在 Eclipse Prolog 中使用 'not' 运算符
using the 'not' operator in Eclipse Prolog
我有一个规则来计算两点之间的距离,我说
distance(X1,Y1,X2,Y2,D) :- at(Car1,X1,Y1), at(Car2,X2,Y2), not(X1=X2),not(Y1=Y2), D is sqrt((X2 - X1)*(X2 - X1) + (Y2 - Y1)*(Y2 - Y1)).
这很好用。 not 操作完全按预期工作。但是后来我有了这个规则。
canTurnLeft(Car,X,Y) :- at(Car,X,Y), light(green,X,Y), not(distance(X,Y,A,B,D), D < 80, oppDir(X,Y,A,B)).
然后吐出来"calling an undefined procedure not(....)"
你能不能在多个 and 上使用 not 运算符?如果不是,我怎么能return如果80个单位内有任何车在相反方向行驶,我怎么会假呢?
Prolog 的新手,非常感谢您的帮助。谢谢
not/1
接受一个参数。但是在你的第二种情况下有 3 个参数。尝试将三个参数括在括号中:
canTurnLeft(Car,X,Y) :-
at(Car,X,Y),
light(green,X,Y),
not((distance(X,Y,A,B,D), D < 80, oppDir(X,Y,A,B))).
一个更简单的例子:
X = 3, not((X = 2, X = 4)).
我有一个规则来计算两点之间的距离,我说
distance(X1,Y1,X2,Y2,D) :- at(Car1,X1,Y1), at(Car2,X2,Y2), not(X1=X2),not(Y1=Y2), D is sqrt((X2 - X1)*(X2 - X1) + (Y2 - Y1)*(Y2 - Y1)).
这很好用。 not 操作完全按预期工作。但是后来我有了这个规则。
canTurnLeft(Car,X,Y) :- at(Car,X,Y), light(green,X,Y), not(distance(X,Y,A,B,D), D < 80, oppDir(X,Y,A,B)).
然后吐出来"calling an undefined procedure not(....)"
你能不能在多个 and 上使用 not 运算符?如果不是,我怎么能return如果80个单位内有任何车在相反方向行驶,我怎么会假呢?
Prolog 的新手,非常感谢您的帮助。谢谢
not/1
接受一个参数。但是在你的第二种情况下有 3 个参数。尝试将三个参数括在括号中:
canTurnLeft(Car,X,Y) :-
at(Car,X,Y),
light(green,X,Y),
not((distance(X,Y,A,B,D), D < 80, oppDir(X,Y,A,B))).
一个更简单的例子:
X = 3, not((X = 2, X = 4)).