GreatDantone
Programmer
Hi, I ave an assignment in wich we need to code an unification algorithm in prolog. I already wrote a predicate
unifier(E1,E2,S). where S is the unification of E1 and E2 if possible.
Example: unifier(a,'A',S) gives
S = [a,'A']
(variables are in quotes to prevent prolog from interpreting them)
I'm trying to write unifier_liste(E1,E2,S), that would do the same for lists. For example:
unifier_liste([a,b,c],['A,'B','C'],S) would give:
S = [[a,'A'],[b,'B'],[c,'C']]
here is the unifier_liste predicate I wrote, though it's not working:
unifier_liste(E1,E2,Sub) :-
\+empty_list(E1), %empty_list fails if E1 != []
E1 = [X1|Y1],
E2 = [X2|Y2],
unifier(X1,X2,S),
unifier_listes(Y1,Y2,S).
unifier_liste(E1,E2,Sub) :-
\+empty_list(E1), %empty_list fails if E1 != []
E1 = [X1|Y1],
E2 = [X2|Y2],
unifier(X1,X2,S),
append(,,L),
unifier_listes(Y1,Y2,L).
when i run unifier_listes([a,b,c],['A','B','C'],S).
with gprolog, it fails.
If anybody knows what's wrong, it would be appreciated!
Thanks
unifier(E1,E2,S). where S is the unification of E1 and E2 if possible.
Example: unifier(a,'A',S) gives
S = [a,'A']
(variables are in quotes to prevent prolog from interpreting them)
I'm trying to write unifier_liste(E1,E2,S), that would do the same for lists. For example:
unifier_liste([a,b,c],['A,'B','C'],S) would give:
S = [[a,'A'],[b,'B'],[c,'C']]
here is the unifier_liste predicate I wrote, though it's not working:
unifier_liste(E1,E2,Sub) :-
\+empty_list(E1), %empty_list fails if E1 != []
E1 = [X1|Y1],
E2 = [X2|Y2],
unifier(X1,X2,S),
unifier_listes(Y1,Y2,S).
unifier_liste(E1,E2,Sub) :-
\+empty_list(E1), %empty_list fails if E1 != []
E1 = [X1|Y1],
E2 = [X2|Y2],
unifier(X1,X2,S),
append(
unifier_listes(Y1,Y2,L).
when i run unifier_listes([a,b,c],['A','B','C'],S).
with gprolog, it fails.
If anybody knows what's wrong, it would be appreciated!
Thanks