This Prolog predicate, I believe, is meant to take a string, which is expressed as a list, a translate it into the accepting language of an fsm. This comes from my AI course, which does everything in Prolog, a language I'm not too experienced with:
str2fsm( [], [], [q0]).
str2fsm( [H|T], Trans, [Last]) :-
mTL( T, [H], [[q0, H, [H]]], Trans, Last).
/* mTL( +More, +LastSoFar, +TransSoFar, ?Trans, ?Last) */
mTL( [], L, Trans, Trans, L).
mTL( [H|T], L, TransSoFar, Trans, Last) :-
mTL( T, [H|L], [ [L,H,[H|L]] | TransSoFar], Trans, Last).
As I said, I'm quite new to Prolog and, despite my attempts to learn how to code with it, I'm simply not used to declarative programming, and understanding the reasoning behind the code is really difficult for me. Any insight as to how this code functions step-by-step would be greatly appreciated (or even a more general overview about how I should be thinking about coding in Prolog). Thanks!