1list_rset([], []). % keep rightmost occurrences
2list_rset([E|Es], Rs0) :-
3 if_(memberd_t(E, Es),
4 Rs0 = Rs,
5 Rs0 = [E|Rs]),
6 list_rset(Es, Rs).
7
8list_lset([], []). % keep leftmost occurrences
9list_lset([E|Es], Ls) :-
10 post_pre_lset(Es, [E], Ls). % uses internal auxilary predicate
11
12post_pre_lset([], _, []).
13post_pre_lset([E|Es], Pre, Ls0) :- % 2nd arg: look-behind accumulator
14 if_(memberd_t(E, Pre),
15 Ls0 = Ls,
16 Ls0 = [E|Ls]),
17 post_pre_lset(Es, [E|Pre], Ls).
18