Files
rose-ash/lib/prolog/tests/programs/reverse.pl
giles 93b31b6c8a
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled
prolog: reverse.pl + reverse.sx (naive via append), 6 tests
2026-04-25 04:26:20 +00:00

8 lines
252 B
Prolog

%% reverse/2 — naive reverse via append/3.
%% Quadratic — accumulates the reversed prefix one append per cons.
reverse([], []).
reverse([H|T], R) :- reverse(T, RT), append(RT, [H], R).
append([], L, L).
append([H|T], L, [H|R]) :- append(T, L, R).