/* Copyright (C) Wolfgang Menzel, Universität Hamburg, 2003-06-27 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. */ %%% a weak error unification %%% collects feature clashes in an additional argument position :- nl. :- write_ln('weak unification'). :- write_ln('call: ?- unify(agr(pl,fem,acc),agr(sg,masc,nom),R,E).'). :- nl. % unify(Term1,Term2,Result,Errors). unify(Term1,Term2,Result,Errors) :- Term1 =.. [Func|ArgList1], Term2 =.. [Func|ArgList2], % same functor in both terms length(ArgList1,L), length(ArgList2,L), % same # of arguments match(Func,ArgList1,ArgList2,ArgListR,Errors), !, Result =.. [Func|ArgListR]. % match(Func,ArgList1,ArgList2,ArglistR,NewErrors). match(_,[],[],[],[]). match(Func,[A1|AR1],[A2|AR2],[A1|ARR],NewErrors) :- % if both arguments are atomic they have to be the same atomic(A1), atomic(A2), A1 = A2, match(Func,AR1,AR2,ARR,NewErrors). match(Func,[A1|AR1],[A2|AR2],[A1|ARR],NewErrors) :- % if at least one of the arguments is a variable: unify (var(A1);var(A2)), A1 = A2, match(Func,AR1,AR2,ARR,NewErrors). match(Func,[A1|AR1],[A2|AR2],[A1|ARR],[ED|NewErrors]) :- % if at least one argument is atomic and the do not unify % produce an error description (atomic(A1);atomic(A2)), A1 \= A2, ED =.. [Func,A1,A2], match(Func,AR1,AR2,ARR,NewErrors). match(Func,[A1|AR1],[A2|AR2],[AR|ARR],Errors) :- % if both arguments are compound terms unify them compound(A1), compound(A2), unify(A1,A2,AR,ED), match(Func,AR1,AR2,ARR,NewErrors), append(ED,NewErrors,Errors).