% append(L1,L2,L3) <=> list concatenation
append([]   ,L,L).
append([E|R],L,[E|RL]) :- append(R,L,RL).


% add an element at the end of a list
add_list(L,E,LandE) :- append(L,[E],LandE).

% compute the last element of a list
last(L,E) :- append(_,[E],L).

% define a predicate member(E,L) <=> E occurs as an element in the list L
member(E,L) :- append(_,[E|_],L).

% deletes an element in a list
delete(L,E,LwithoutE) :- append(L1,[E|L2],L), append(L1,L2,LwithoutE).

% sublist(T,L) <=> T is a sublist of L
sublist(T,L) :- append(L1,TL2,L), append(T,L2,TL2).
