Prolog Compare elements of list
<p>When given some input list, I want to build a new list and it should:</p>

<ul>
<li>Always add h in front of the new list</li>
<li>Compare every two consecutive elements of the input list, and, if they are
equal, append y to the new list, if not, append x.</li>
</ul>

<p>Example:</p>

<pre><code>?- control([a,a,b,b],R).
R = [h,y,x,y].
</code></pre>

<p>Here is my code so far:</p>

<pre><code>control([H,H|T],K,[K,0|T2]):- control([H|T],[K,0],T2).
control([H,J|T],K,[K,1|T2]):- control([J|T],[K,1],T2).
control([H],G,G).
</code></pre>

<p>But it is not working correctly.</p>

<pre><code>?-  control([a,a,b,b],[h],L).
L = [[h], 0, [[h], 0], 1, [[[h], 0], 1], 0, [[[...]|...], 1], 0] ;
L = [[h], 0, [[h], 0], 1, [[[h], 0], 1], 1, [[[...]|...], 1], 1] ;
L = [[h], 1, [[h], 1], 1, [[[h], 1], 1], 0, [[[...]|...], 1], 0] ;
L = [[h], 1, [[h], 1], 1, [[[h], 1], 1], 1, [[[...]|...], 1], 1] ;
false.
</code></pre>

<p>How can I make it correct?</p>