append([],L,L). append([A|X],Y,[A|Z]) :- append(X,Y,Z). cons(X,Y,[X|Y]). flatten([H|T], RESULT) :- ( atom(H), flatten(T,Rt), cons(H,Rt,RESULT) ) ; ( flatten(H,Rh), flatten(T,Rt), append(Rh,Rt,RESULT) ) . flatten([],[]). skeleton([H|T], RESULT) :- ( H==[], skeleton(T,Rt), cons(H,Rt,RESULT) );( atom(H), skeleton(T,RESULT) ) ; ( skeleton(H,Rh), skeleton(T,Rt), cons(Rh,Rt,RESULT) ) . skeleton([],[]).