开发者

Compare two atoms in Prolog

开发者 https://www.devze.com 2023-01-14 18:08 出处:网络
I have been learning prolog.. I\'m using a editor named prol1.1.1 I need to write rule to compare 2 strings, when i give something l开发者_开发问答ike

I have been learning prolog.. I'm using a editor named prol1.1.1 I need to write rule to compare 2 strings, when i give something l开发者_开发问答ike

rel(a1,b1).
rel(a2,b2).
rel(b2,c2).

associatedWith(X,Y,Z) :- rel(X,Y),rel(Y,Z).

?- associatedWith(X,Y,Z).

it works

but when i give

?- associatedWith(X,Y,Z),X=\=Z.

i get parser exception

Parser exception [Should be evaluable ''a2''[7:31]] line 7:31 

what i got from websites is =\= is for numeric values, i wasn't able to get answer for comparing string values.. can anyone help me..

and i wasn't able to get gui for swi-prolog can u please help me with that too? i need to use the call prolog from java program and the output has to be again processed in java, can anyone please help me..


You are trying to compare atoms, not strings. Anyways, you need \=

 ?- aaa = aaa.
true.

 ?- aaa \= aaa.
false.

 ?- aaa \= aab.
true.
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号