Compare two atoms in Prolog
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.
精彩评论