Does it matter that the values are two-dimensional coordinates? Is there an ordering on them that you must respect, or is it simply the ordering of the elements in the list? I will assume the latter.
If you want to split a list at some point, the standard append/3
predicate is usually the way to go. For example, assume we want to cut the list [a, b, c, d, e]
into a prefix containing the elements before c
and a suffix containing the elements after c
. Here is how that is done:
?- append(Prefix, [c | Suffix], [a, b, c, d, e]).
Prefix = [a, b],
Suffix = [d, e] ;
false.
Here c
is excluded from the prefix, but that's easy to fix:
?- append(Prefix, [c | Suffix], [a, b, c, d, e]), append(Prefix, [c], UpToAndIncludingC).
Prefix = [a, b],
Suffix = [d, e],
UpToAndIncludingC = [a, b, c] ;
false.
We can give this predicate a nice name:
list_pivot_prefix(List, Pivot, Prefix) :-
append(Prefix0, [Pivot | _Suffix], List),
append(Prefix0, [Pivot], Prefix).
And your find_list/3
predicate then simply finds all the lists in the given list of lists for which this relation holds:
find_list(Lists, Element, Prefix) :-
member(List, Lists),
list_pivot_prefix(List, Element, Prefix).
Here is your test case:
?- find_list([[(1,2),(1,3),(1,4)],[(2,2),(2,3),(2,4)]],(1,3),List2).
List2 = [ (1, 2), (1, 3)] ;
false.