% reverse(X, Z) is true iff list Z is the reverse of list X.

reverse(X, Z) :- reverse(X, [], Z).


% reverse(X, Y, Z) is true iff list Z is the reverse of X appended to Y.
% This is used mostly as the auxiliary function for the reverse above.
% The second argument acts as an accumulator.

reverse([], Z, Z).

reverse([A | X], Y, Z) :- reverse(X, [A | Y], Z).

