I'm searching for an opportunity to slice a list into smaller lists, like that:
[1,2,3,4] -> [[1,2],[2,3],[3,4]]
[1,2] -> [[1,2]]
and so on..
First, I searched for an solution with build-in predicates. But I couldn't figure it out to do it with them.. Is this right?! So I wrote an own predicate:
slice([],[]).
slice([H1,H2|T], Output) :-
append([H2],T,New),
slice(New, [[H1,H2]|Output]).
But in the last iteration step, when New only consists of one element, the unification with [H1,H2|T] fails..