/* Nrev benchmark in Picat. http://www.jekejeke.ch/idatab/doclet/prod/en/docs/05_run/15_stdy/06_bench/09_programs/01_nrev/01_nrev.p.html This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ % import util. % import cp. main => time(go). /** * Prolog code for the naïve reverse benchmark. * * This is the benchmark of page 219 of: * Warren, D.H.D. (1983): Applied Logic – Its Use and * Implementation as a Programming Tool, * Technical Note 290, SRI International, 1983 * */ % Prolog code /* rev([],[]). rev([X|Rest],Ans) :- rev(Rest,L), concatenate(L,[X],Ans). concatenate([],L,L). concatenate([X|L1],L2,[X|L3]) :- concatenate(L1,L2,L3). datanrev([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20, 21,22,23,24,25,26,27,28,29,30]). nrev :- datanrev(X), rev(X,_). */ rev([],Y) => Y = []. rev([X|Rest],Ans) => rev(Rest,L), concatenate(L,[X],Ans). concatenate([],L,L2) => L2 = L. concatenate([X|L1],L2,LL) => LL = [X|L3], concatenate(L1,L2,L3). datanrev(D) => D = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20, 21,22,23,24,25,26,27,28,29,30]. % go => datanrev(X), rev(X,_). go => datanrev(X), rev(X,Y), writeln(Y). go2 => datanrev(X), rev(X,_Y).