Compare two atoms in Prolog

I am studying the prologue .. I am using an editor called prol1.1.1 I need to write a rule to compare 2 lines 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).

works

but when i give

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

I get a parser exception

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

what I got from web sites = \ = for numeric values, I could not get an answer to compare string values ​​.. can someone help me ..

and i could not get gui for swi-prolog, maybe please help me with this? I need to use the call prolog from a java program, and the result should be processed again in java, can anyone help me ..

+3
source share
1 answer

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

 ?- aaa = aaa.
true.

 ?- aaa \= aaa.
false.

 ?- aaa \= aab.
true.
+5
source

Source: https://habr.com/ru/post/1763355/


All Articles