Warning! It seems that you are using Dodona within another webpage, so not everything may work properly. Let your teacher know so that he can solve the problem by adjusting a setting in the learning environment. In the meantime, you can click this link to open Dodona in a new window.
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.