title: Sort deep list by depth prolog
body: <p>I want to sort a deep list by the depth of each list. But my code only separates the elements, not sorting them. By far, I don't have knowledge about difference lists to sort them in other way, so please let me see what is wrong with my code.</p>
  
  <pre><code>insert_ord(X, [H|T], [H|R]):- 
       X &gt; H, !, 
       insert_ord(X, T, R).
  insert_ord(X, T, [X|T]).
  
  ins_sort([H|T], R):- 
       ins_sort(T, R1), 
       insert_ord(H, R1, R).
  ins_sort([], []).
  
  ord([H|L], [R1|R]):-
       is_list(H),
       ord(H, R1),
  ord(L,R).
  
  ord(L,R):-
       ins_sort(L, R).
  ord([],[]).
  </code></pre>
  
  <p>So, this predicate should produce the following result:</p>
  
  <pre><code>ord([[[[1]]], 2, [5,[4],7], [[5],4], [5,[0,9]]], R).
  
  R = [2, [5,[0,9]], [[5],4], [5,[4],7], [[[1]]]] ;
  false
  </code></pre>