Just answering, so that the question goes off the list of unanswered
questions: Yes the (;)/2 is a problem. Further if you really only
want a yes or no, you could also try memberchk/2 instead of member/2.
The code would read:
line(1,[a,b,c,d,e]).
line(2,[b,g,f,e,i,h]).
line(3,[l,m,g,n,f,o,p,q,i,j]).
same_linechk(X,Y):-
line(_,L),
memberchk(X,L),
memberchk(Y,L).
And works as expected:
?- same_linechk(n,j).
true.
The predicate memberchk/2 is part of SWI-Prolog and does not
backtrack after the first time it has found a matching member.
It is essentially a menber/2 with a builtin cut and thus in
the average twice as fast.
Bye