Prolog Remove the elements between the first and the last elements in a list
问题 I am trying to keep only the first element and the last element for a list which contains only consecutive integers. For example: ?- remove([1,2,3,4,5], NewList). NewList = [1,5]. I can only successfully keep the last element: remove([], []). % for consecutive integers in the list remove([ Head | Tail ], NewList) :- check_consecutive(Head, Tail), remove(Tail, NewList). % for the case when the list is empty remove([ Head | Tail ], [ Head | NewList ]) :- not(check_consecutive(Head, Tail)),