I am a beginner to Prolog and I would like to ask a question about Prolog.
My program is based on non-deterministic finite-state automaton.
the start state is S0 and the final state is S3.
The diagram is

so if there is a string [a,a,b,b,c,c] it should be like
start(s0).
edge(a, s0, s0).
edge(a, s0, s1).
edge(b, s1, s1).
edge(b, s1, s2).
edge(c, s2, s2).
edge(c, s2, s3).
final(s3).
There is a predicate accepts(Ls) if (there Ls is a list of string)
accepts(Ls) :- start(A), goesTo(Ls, A, B), final(B).
and assuming that the NFA goes from state Si to state Sj and in between them there is a state Sk, goesTo predicate is defined as
goesTo(Ls, Si, Sj) :- edge (L, Si, Sk), goesTo(Ls, Sk, Sj).
But if querying accepts(Ls) (any arbitrary list of string ranging from a to c)
the tutorial question says that it will almost certainly go into an infinite search and stack overflow will occur.
However, I don't understand why the query will go into an infinite search and cause stack overflow. If you can give me the reason, it would be really great!
(edit:) the exact quote is:
"a typical Prolog user might hope that his/her goesTo rules would be such tat the query accepts(X) would generate successive strings that are accepted by the NFA above. Almost certainly, given the above presentation of the given NFA, the Prolog system will go into an infinite search and stack overflow will occur. Say why this is so. (if your goesTo avoid this problem, say how you managed to avoid it)."