# Różnice

Różnice między wybraną wersją a wersją aktualną.

 — pl:prolog:pllib:unification [2019/06/27 15:50] (aktualna) Linia 1: Linia 1: + ====== Unification ====== + {{tag>​terms}} + ===== Description ===== + Unification algorithm + + **Source**: ​ The Art of Prolog + ===== Download ===== + Program source code: {{unification.pl}} + ===== Listing ===== + + /* + ​unify(Term1,​Term2) :- + Term1 and Term2 are unified, ignoring the occurs check. + */ + ​unify(X,​Y) :- + var(X), var(Y), X=Y. + ​unify(X,​Y) :- + var(X), nonvar(Y), X=Y. + ​unify(X,​Y) :- + var(Y), nonvar(X), Y=X. + ​unify(X,​Y) :- + nonvar(X), nonvar(Y), constant(X),​ constant(Y),​ X=Y. + ​unify(X,​Y) :- + nonvar(X), nonvar(Y), compound(X),​ compound(Y),​ term_unify(X,​Y). + + ​term_unify(X,​Y) :- + functor(X,​F,​N),​ functor(Y,​F,​N),​ unify_args(N,​X,​Y). + + ​unify_args(N,​X,​Y) :- + N > 0, unify_arg(N,​X,​Y),​ N1 is N-1, unify_args(N1,​X,​Y). + ​unify_args(0,​X,​Y). + + ​unify_arg(N,​X,​Y) :- + arg(N,​X,​ArgX),​ arg(N,​Y,​ArgY),​ unify(ArgX,​ArgY). + + + %  Program 10.5    Unification algorithm + + ​ + ===== Comments =====
pl/prolog/pllib/unification.txt · ostatnio zmienione: 2019/06/27 15:50 (edycja zewnętrzna)