title: Prolog insert integer after every non integer element
body: <p>I have the list <code>[r,s,2,t,3,u,v]</code> and I need to make a list that will look like <code>[r,5,s,2,t,3,u,5,v,5]</code>. The rule is: for every non integer that is not followed by an integer, a <code>5</code> will be added after that element.</p>
  
  <p>I am new to Prolog and this is my code so far:</p>
  
  <pre><code>insertInL([],[]).
  insertInL([F,S|Tail], [F,X|Rest]) :- 
       integer(S), X = S, insertInL(Tail, Rest).
  </code></pre>
  
  <p>I know there should be one case where S is not an integer but I don't know hot to treat it.</p>
  
  <p>Edit:<br>
                                                                                   I renewed my code:</p>
  
  <pre><code>insertInL([],[]).
  insertInL([F,S|T1], [F,S|T2]) :- 
      integer(S), insertInL(T1, T2).
  insertInL([F,S|T1], [F,1|T2]) :- 
      \+ integer(S), insertInL([S|T1], T2).
  </code></pre>
  
  <p>Now it does fine unless I have a non integer as last element.</p>
  
  <p>Edit2:<br>
  Now it works properly.</p>
  
  <pre><code>insertInL([],[]).
  insertInL([F],[F,1]) :-
      \+ integer(F).
  insertInL([F,S|T1], [F,S|T2]) :- 
      integer(S), insertInL(T1, T2),!.
  insertInL([F,S|T1], [F,1|T2]) :- 
      \+ integer(S), insertInL([S|T1], T2).
  </code></pre>