This predicate can be used to select an element from a list, delete an element or insert it.
The definition of this Prolog library predicate is:
select(A, [A|B], B). select(A, [B, C|D], [B|E]) :- select(A, [C|D], E).This predicate does not perform any type testing functions.
Success: [eclipse]: select(X,[1,M,X],L), writeln((M,X,L)), fail. _g66 , 1 , [_g66, 1] _g66 , _g66 , [1, _g66] _g66 , _g72 , [1, _g66] no (more) solution. [eclipse]: select(3,[1,3,5,3],L). L = [1, 5, 3] More? (;) L = [1, 3, 5] yes. [eclipse]: select(X,L,[a,b]), writeln((X,L)), fail. _g66 , [_g66, a, b] _g66 , [a, _g66, b] _g66 , [a, b, _g66] no (more) solution. select(X,[1,2],L). (gives X=1 L=[2]; X=2 L=[1]). Fail: select(1,[1,2,1,3],[2,3]).