Prolog Lists and Internal Variables
<p>I have a created a predicate that finds a path through a maze, this predicate uses recursion and five parameters, and one of which is a list that returns the path found, everything works fine and the correct path is found but when the list is returned an Prolog internal variable is returned with it.</p>

<pre><code>?- maze(X).
X = [start,x,z,s,r,p,q,l,m,w,d,r,l,s,a,t,c,i,d,b,j,k,g|_G2612] .
</code></pre>

<p>the first node is 'start' and the final node is 'g'.</p>

<p>example code:</p>

<pre><code>maze(X) :-
    path(start,colour,g,[],X).

path(From, Colour, To, Visited, [From,To|_]) :-
    connect(From, Colour, To).
path(From, Colour, To, Visited, [From|Route]) :-
    connect(From, Colour, By),
    path(By, Colour2, To, Visited2,Route).
</code></pre>

<p>I have removed steps within the predicates that doesn't affect the question because this is an assignment where you have to find the path using some other variables.</p>