I have the following code to group sequences of equivalent objects together:
pack([], []).
pack([X], [X]).
pack([H, T|TS], [H|TR]):-
H \= T,
pack([T|TS], TR).
pack([H, H|HS], [[H|TFR]|TR]):-
pack([H|HS], [TFR|TR]).
My input is:
pack([1,1,1,1,2,3,3,1,1,4,5,5,5,5], X).
And as a result I get:
[[1,1,1|1],2,[3|3],[1|1],4,[5,5,5|5]]
Have you noticed | sign before the last element in each list? I do not know why it appears and how to fix it. Any ideas?