% -*- prolog -*-

% rev1([a,b,c], [c,b,a])

rev1([], []).
rev1([A|X], Y) :- rev1(X, Y1), app(Y1, [A], Y).

%%% rev2aux(X, Y, Z) means Z is the appending of the reverse of X with Y.

rev2(X, Y) :- rev2aux(X, [], Y).

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

% rev2aux([a,b,c], [1,2,3], [c,b,a,1,2,3]).
% rev2aux([b,c], [a,1,2,3], [c,b,a,1,2,3]).
% rev2aux([c], [b,a,1,2,3], [c,b,a,1,2,3]).
% rev2aux([], [c,b,a,1,2,3], [c,b,a,1,2,3]).

%%% iota's second argument must be a number.
iota([], 0).
iota([M|X], N) :- N > 0, M is N-1, iota(X, M).

% iota([], 0).
% iota([0], 1).
% iota([1 0], 2).
% iota([2 1 0], 3).
% iota([3 2 1 0], 4).
