I\'ve got here a small script, that converts list of elements into a set. For example list [1,1,2,3] -> set [1,2,3]. Can somebody explain to me, step by step, whats happenin
In certain implementations of Prolog, e.g. GNU Prolog, you can trace the execution of your code. Using this feature you can step through the evaluation process, as demonstrated below.
$ gprolog
GNU Prolog 1.4.2
By Daniel Diaz
Copyright (C) 1999-2012 Daniel Diaz
| ?- consult('list_to_set.pro').
yes
| ?- trace.
yes
{trace}
| ?- list_to_set([1,1,2,3], X).
1 1 Call: list_to_set([1,1,2,3],_25) ?
2 2 Call: list_to_set([1,2,3],_57) ?
3 3 Call: list_to_set([2,3],_83) ?
4 4 Call: list_to_set([3],_109) ?
5 5 Call: list_to_set([],_135) ?
5 5 Exit: list_to_set([],[]) ?
6 5 Call: \+member(3,[]) ?
7 6 Call: member(3,[]) ?
7 6 Fail: member(3,[]) ?
6 5 Exit: \+member(3,[]) ?
4 4 Exit: list_to_set([3],[3]) ?
7 4 Call: \+member(2,[3]) ?
8 5 Call: member(2,[3]) ?
...
An explanation of how to interpret Prolog's traces can be found at http://remus.rutgers.edu/cs314/f2007/ryder/projects/prolog/prologTrace.html, section READING A TRACE.