title: Transposing a Matrix in prolog
body: <p>I have written the following code below to transpose a Matrix in prolog</p>
  
  <pre><code>listFirst([],[]).
  listFirst([H1|T1],[H2|Z]):-
      H1 = [H2|_],
      listFirst(T1,Z).
  
  listFollowers([],[]).
  listFollowers([H1|T1],[T2|Z]):-
      H1 = [H2|T2],
      listFollowers(T1,Z).
  
  decompose(A,L1,L2):-
      listFollowers(A,L2),listFirst(A,L1).
  
  transpose([],[]).
  transpose([H|T],[L1|R]):-   
      decompose([H|T],L1,L2),
      transpose(L2,R).
  </code></pre>
  
  <p>Test Case</p>
  
  <pre><code>transpose([[1,2],[3,4],[5,6]], R).
  R = [[1,3,5],[2,4,6]] ;
  </code></pre>
  
  <p>I am having problems with the transpose predicate no sure how to implement this. Other predicates seem to work okay.</p>