%%% -*- prolog -*-

%%% DIFFERENCE LISTS

%% represents a list of three elements: [a,b,c]
%% diff( [a,b,c | Xs], Xs )
%% diff( [a,b,c], [] )
%% diff( [a,b,c,d,e,f,g], [d,e,f,g] )

undiff( diff(Xs,Ys) , Zs ) :- append(Zs, Ys, Xs).

% | ?- undiff( diff([a,b,c,d], [d]), Es).
% Es = [a,b,c]

% | ?- undiff(DL, [a,b,c]).                   
% DL = diff([a,b,c|A],A)

dlAppend( diff(X, Y), diff(Y, Z), diff(X, Z) ).

% | ?- undiff(Xd, [a,b,c]), undiff(Yd, [d,e,f]), dlAppend(Xd, Yd, Zd).

% Xd = diff([a,b,c,d,e,f|A],[d,e,f|A])
% Yd = diff([d,e,f|A],A)
% Zd = diff([a,b,c,d,e,f|A],A)
