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?
In Prolog I see tracing is as a method of last resort. Whenever I'm tempted to start up the tracer, I think of the endless hours I have spent tracing codes to no avail.
In retrospect I could have spent that time way better doing the following activities:
Note to self: read this post when feeling the urge to start the tracer:)