I wanted something with this behavior:
closed_to_open_list( [a,b,c], X ).
X = [a, b, c|_22434] ;
This feels faintly ridiculous, but I couldn't find any easy way to do this. As much as anything, I don't know how to define an "empty open list", i.e. a list that is essentially just an anonymous tail. I can of course define a list with an anonymous tail that has at least one element as its head.
I ended up with this silly-looking thing that works (so long as Closed has at least one element):
closed_to_open_list( [X], [X|_] ).
closed_to_open_list( Closed, Open ) :-
length( Closed, N ),
N > 1,
AllBut1 is N - 1,
last( Closed, CLast ),
firstNOf( AllBut1, Closed, CFirstList ),
append( CFirstList, [CLast|_], Open ).
What am I missing here?