Unify with occurs check

Sign in to test your solution.
% 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) :- nonvar(X), var(Y), X=Y. unify(X, Y) :- nonvar(X), nonvar(Y), atomic(X), atomic(Y), X=Y. unify(X, Y) :- nonvar(X), nonvar(Y), compound(X), compound(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, _, _). unify_arg(N, X, Y) :- arg(N, X, ArgX), arg(N, Y, ArgY), unify(ArgX, ArgY).
You can submit as many times as you like. Only your latest submission will be taken into account.
Sign in to test your solution.