% -*- Prolog -*-
%
% nrev + types. Polymorphic.
%
% $Id: 202,v 1.15 2000/11/13 11:55:05 peteg Exp $

:- list(X) ::= [] ; [X | list(X)].
:- compile(append/3).

% append/3 - concat two lists in order
append([X|Xs], Y, [X|Zs]) :-
	append(Xs, Y, Zs).
append([], X, X).
% Normalised:
%append(_A0, _B0, _C0) :-
%        unify(_A0, [_D0|_E0]),
%        unify(_C0, [_F0|_G0]),
%        unify(_D0, _F0),
%        append(_E0, _B0, _G0).
%append(_A0, _B0, _C0) :-
%        unify(_A0, []),
%        unify(_B0, _C0).

% nrev/2 - naive reverse
nrev([],[]).
nrev([X|Xs],Zs) :-
	nrev(Xs,Ys),
	append(Ys,[X],Zs).
% Normalised:
%nrev(_A0, _B0) :-
%        unify(_A0, []),
%        unify(_B0, []).
%nrev(_A0, _B0) :-
%        unify(_A0, [_C0|_D0]),
%        nrev(_D0, _E0),
%        unify(_F0, [_G0|_H0]),
%        unify(_C0, _G0),
%        unify(_H0, []),
%        append(_E0, _F0, _B0).

% nrev 30 has 496 logical inferences
nrev30 :- nrev([1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0], X).

%main :-
%	nrev([1,2,3,4,5,6], X),
%	write(X), nl, fail.

% Benchmarking
benchmark :-
	benchmark(200).

benchmark(0) :- !.
benchmark(X) :-
	nrev30,
	X0 is X - 1,
	benchmark(X0).
