views:

81

answers:

1

hi,

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 like

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..

A: 

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

 ?- aaa = aaa.
true.

 ?- aaa \= aaa.
false.

 ?- aaa \= aab.
true.
Xonix
Actually, it's more commonly `\+(A == B)` or `A \== B` for inequality of terms. `A \= B` is short for `\+ (A = B)`, i.e., is not unifiable.
sharky