So I am trying to trace this "sublist" code and I really need help...
This function basically check to see if second list is sublist of the first list where order DOES matter;
(1) isSublist([],[]).
(2) isSublist([H1|T1], [H1|T2]) :- isSublist(T1,T2),!.
(3) isSublist([_|T1], T2) :- isSublist(T1,T2).
What I am getting confused is that how is H1 being recognized? For example, if input was sublist [1,4,7,9],[4,7], and having same H1, does it overlap? or will it have [1|4,7,9],[4|7] ? Even though H1 does not get used in the conditions, taking them out or assigning H1 and H2 does effect the result...
Also second question is, after checking second condition (2), does it go down to the next condition with updated list? or does it go up go base case (1)" ?
Even if it goes to the base case (1) or (3), all I see it does is getting rid of the head until both of the list is empty... Can you explain how this code is working? Maybe hint of how to trace it even?
I'm not sure you have realy understood how prolog works. Perhaps you need to read a guide or something.
In you're case, Each time you call isSublist, prolog will choose the first definition maching the given parameters. It will choose between (2) and (3) until it reach the (1) statement that returns true. If prolog can't find a path to the (1) statement, it will return false.
You can also notice the '!' telling to prolog to stop backtracking form this point.
I hope this will help you but like I said, I think you need to read more about prolog and his special paradigm. It's not easy to understand by only reading code. If you want, I have found this book really good for a starting point, it's well explained : Learn Prolog Now!
Like said in comments, you can use
?- trace.to enter in trace mode. See the prolog documentation for more information about it.