dfs in prolog. Visiting a node once
<pre><code>dfs(S, Visited, Path) :-
    move(S, S2),
    \+member(S2, Visited),
    dfs(S2, [S2|Visited], Path).
</code></pre>

<p>Hi,</p>

<p>Above piece of code is a prototype of dfs in Prolog. But, <code>move</code> bases on backtracking and because of that fact I lose <code>Visited</code> list so it is impossible to make sure that I visit every node once.
How to deal with it without using global variable and similar to it- I would like use pure logical solution.</p>