I have this predicate spaces_uni(Spc,LstWords)
, Spc is a list of variables like [X,Y,Z]
or [a,Y,Z]
and LstWords is a list of words like [[o,r,a,n,g,e],[a,p,p,l,e],[b,a,n,a,n,a]]
.
The purpose of this predicate is to check if there is any word in LstWords that can unify with the given Spc.
Example:
?- Words = [[a,m,e,n,o],[a,t,o],[d,a,o],[d,r,a,m,a],[m,a,e],[m,a,n,d,e],[s,e,d,e],[s,o,a,r]], Space = [d,A,B,C,D], spaces_uni(Space,Words).
true.
So why is the output true, simple, its because the word drama unifies with [d,A,B,C,D] becoming [d,r,a,m,a]. The problem is that my program is instead returning false and i dont understand why.
Program:
spaces_uni(E,[P|R]) :-
length(E,CE),
length(P,CP),
CE \== CP,!,
spaces_uni(E,R).
spaces_uni(E,[P|R]) :-
length(E,CE),
length(P,CP),
CE == CP,!,
P \= E,
spaces_uni(E,R).
spaces_uni(E,[P|_]) :-
length(E,CE),
length(P,CP),
CE == CP,
{}/(P = E),!,
true.
Really any help would be appreciated.