% -*- prolog -*-

%%% Trick: represent list of items a,b,c,d as [a,b,c,d|Hole]-Hole

%%% [A|L2]-L3  is list that starts with elt A, continues w/ L2-L3.

%%% append using difference lists

app_dl(L1-L2, L2-L3, L1-L3).

%%% reverse

% to reverse [a,b,c|H]-H ...
% reverse [b,c|H]-H is [c,b|I]-I ... appended with [a|J]-J ... gives answer

% empty list is reverse of empty list:
rev_dl(H1-H1, H2-H2).

% reverse of list starting with A and continuing w/ L2-L3 is
% reverse of L2-L3, appended with a singleton list contining A.

rev_dl([A|L2]-L3, L4-L5) :- rev_dl(L2-L3, X-Y), app_dl(X-Y, [A|H]-H, L4-L5).
