title: Prolog Zip Function
body: <p>Im in rew to Prolog. I'm trying to write a <code>zip</code> function. The question goes like this.</p>
  <p><code>zip(L1, L2, X)</code>: The list <code>X</code> is formed by “zipping” the first 2 arguments.</p>
  <p>the result should be like this:</p>
  <pre><code>?- zip([a, b, c], [x, y, z], X).
  L = [a, x, b, y, c, z]
  ?- zip([a, b], [x, y, z], X).
  false
  ?- zip([a, b, c, d], X, [a, p, b, q, c, r, d, s]).
  X = [p, q, r, s]
  </code></pre>
  <p>I have done this so far.
  I can get the result for 1st 3rd but not the 2nd one. Can anybody can help me solving it for the 2nd one? thank you</p>
  <pre><code>zip([X],[Y],[X,Y]).  
  zip([], [], []).
  zip([X|Xs], [Y|Ys], [X,Y|Zs]) :-
     zip(Xs,Ys,Zs).
  
  zip([X|Xs],[],[X|Xs]).
  zip([Y|Ys],[],[Y|Ys]).
  
  zip(Xs, [], Xs).
  zip([], Ys, Ys).
  </code></pre>
  <p>How do I define this function where:
  <code>allsame(L)</code>: The list <code>L</code> contains identical elements.
  I should get this.</p>
  <pre><code>?- allsame([b, b, b]).
  true
  ?- allsame([c, c, c, Y, c, c, X, c]).
  X = c, Y = c
  </code></pre>