list([]).
list([_|_]).

% Flatten

flatten([],[]).
flatten([H|T],O) :- list(H), !, flatten(H,O1), flatten(T,O2), append(O1,O2,O).
flatten([H|T],[H|O]) :- flatten(T,O).

% Flatten with difference lists

flattendl([],X,X).
flattendl([H|T],Y1,Y) :- list(H), !,
	flattendl(H,Y1,Y2),
	flattendl(T,Y2,Y).
flattendl([H|T], [H|Y1],Y) :- flattendl(T,Y1,Y).