Hello I'm doing a project on prolog and still grasping with the language. I currently have a list of lists, in which the sublists have coordinates.
My aim is to select the sublist with a certain coordinate X and then to cut that list from it's first element up to X. (only one list)
I thought that at first the problem would to be to select the sublist with member. So I tried to do so.
sublist([],_, []).
sublist([H|R],Pos, [H|Aux]) :-
member(Pos,H), !,
sublist(R,Pos, Aux).
sublist([H|R],Pos, Aux) :-
sublist(R,Pos,Aux).
This doesn't work:
?- sublist([[(1,2),(1,3),(3,5)],[(1,5),(1,2)]], (1,5), X).
X = [].
What I wanted for this first stage was something like:
?- sublist([[(1,2),(1,3),(3,5)],[(1,5),(1,2)]], (1,5), X).
X = [(1,5),(1,2)].
(afterwards, when I have the sublist selected I planned on doing a similar thing in which I add elements to an empty list until the element equals X).
So that the end result would be:
?- sublist([[(1,2),(1,3),(3,5)],[(1,5),(1,2)]], (1,5), X).
X = [(1,5)].
What am I doing wrong? I'm still learning to think in Prolog so I apologize for obvious logic mistakes.