I have been looking for a predicate to split a list L into three pieces:
- Front (a list)
- Element at Index N (0-based)
- Back (a list)
Here is one. It is still not predicatly enough and unable to compute Index or List from the other parameters.
% split_list(+List, +Index, Element, Front, Back) split_list([L|Lr], N, El, [L|Front], Back) :- N>0,!, Nm is N-1, split_list(Lr,Nm,El,Front,Back). split_list([L|Lr], 0, L, , Lr).